Strip comments from a string: Difference between revisions
Content added Content deleted
Alextretyak (talk | contribs) (Added 11l) |
(Updated to work with Nim 1.4: added missing parameter types. Changed output.) |
||
Line 1,184: | Line 1,184: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
<lang nim>import strutils |
<lang nim>import strutils |
||
proc removeComments(line |
proc removeComments(line: string; sep: char): string = |
||
line.split(sep)[0].strip(leading = false) |
line.split(sep)[0].strip(leading = false) |
||
const |
|||
⚫ | |||
⚫ | |||
echo "Original: “$#”" % Str1 |
|||
echo "Stripped: “$#”" % Str1.removeComments('#') |
|||
echo "Original: “$#”" % Str2 |
|||
echo "Stripped: “$#”" % Str2.removeComments(';')</lang> |
|||
{{out}} |
|||
⚫ | |||
<pre>Original: “apples, pears # and bananas” |
|||
⚫ | |||
Stripped: “apples, pears” |
|||
Original: “apples, pears ; and bananas” |
|||
Stripped: “apples, pears”</pre> |
|||
=={{header|Objeck}}== |
=={{header|Objeck}}== |