Strip comments from a string: Difference between revisions
Rename Perl 6 -> Raku, alphabetize, minor clean-up
Thundergnat (talk | contribs) (Rename Perl 6 -> Raku, alphabetize, minor clean-up) |
|||
Line 212:
apples, pears,
</pre>
=={{header|AutoIt}}==
Line 419 ⟶ 418:
The modified string is : apples, pears
Do you want to repeat (y/n): n
</pre>▼
=={{header|C sharp|C#}}==▼
<lang csharp>▼
using System.Text.RegularExpressions;▼
string RemoveComments(string str, string delimiter)▼
{▼
//regular expression to find a character (delimiter) and ▼
// replace it and everything following it with an empty string.▼
//.Trim() will remove all beginning and ending white space.▼
return Regex.Replace(str, delimiter + ".+", string.Empty).Trim();▼
}▼
</lang>▼
Sample output:▼
<pre>▼
Console.WriteLine(RemoveComments("apples, pears # and bananas", "#"));▼
Console.WriteLine(RemoveComments("apples, pears ; and bananas", ";"));▼
apples, pears▼
apples, pears▼
</pre>
Line 450 ⟶ 470:
apples, pears
apples, pears ; and bananas
▲apples, pears
▲</pre>
▲=={{header|C sharp|C#}}==
▲<lang csharp>
▲using System.Text.RegularExpressions;
▲string RemoveComments(string str, string delimiter)
▲ {
▲ //regular expression to find a character (delimiter) and
▲ // replace it and everything following it with an empty string.
▲ //.Trim() will remove all beginning and ending white space.
▲ return Regex.Replace(str, delimiter + ".+", string.Empty).Trim();
▲ }
▲</lang>
▲Sample output:
▲<pre>
▲Console.WriteLine(RemoveComments("apples, pears # and bananas", "#"));
▲Console.WriteLine(RemoveComments("apples, pears ; and bananas", ";"));
▲apples, pears
apples, pears
</pre>
Line 885 ⟶ 884:
}
}</lang>
=={{header|JavaScript}}==
Line 1,262 ⟶ 1,260:
print
}</lang>
=={{header|Perl 6}}==▼
<lang perl6>$*IN.slurp.subst(/ \h* <[ # ; ]> \N* /, '', :g).print</lang>▼
=={{header|Phix}}==
Line 1,475 ⟶ 1,470:
(strip-comments2 text) ; -> "apples, pears\napples, pears"
</lang>
(formerly Perl 6)
▲<lang perl6>$*IN.slurp.subst(/ \h* <[ # ; ]> \N* /, '', :g).print</lang>
=={{header|Red}}==
|