Reputation: 550
I want to remove anything after // to the end.
Example:
Pickup0=1240,-2572.2773,651.0634,33.8931,-1 // text
Pickup1=1242,-2564.4270,651.1445,33.8931,-1 // text
Pickup2=358,-2559.6565,636.4931,14.4592,-1 // text42434
Pickup3=356,-2573.4871,636.5174,14.4592,-1 // blabla
I want it to be:
Pickup0=1240,-2572.2773,651.0634,33.8931,-1
Pickup1=1242,-2564.4270,651.1445,33.8931,-1
Pickup2=358,-2559.6565,636.4931,14.4592,-1
Pickup3=356,-2573.4871,636.5174,14.4592,-1
I could do it with this code, but it only removes the // one time and not all of them.
textBox1.Text = Regex.Replace(textBox1.Text, @"\//.*$", "");
Upvotes: 3
Views: 57
Reputation: 70732
You need to turn on the m
(multi-line) modifier which causes $
to match the end of each line.
Regex.Replace(textBox1.Text, @"(?m)//.*$", "");
But the end of string $
anchor is not necessary to use in this case because .*
will match any character except newline, so you could just simply remove it from your regular expression.
Regex.Replace(textBox1.Text, @"//.*", "");
Upvotes: 5