Strip comments from a string: Difference between revisions

Content added Content deleted
(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, sep): string =
proc removeComments(line: string; sep: char): string =
line.split(sep)[0].strip(leading = false)
line.split(sep)[0].strip(leading = false)
const
Str1 = "apples, pears # and bananas"
Str2 = "apples, pears ; and bananas"

echo "Original: “$#”" % Str1
echo "Stripped: “$#”" % Str1.removeComments('#')
echo "Original: “$#”" % Str2
echo "Stripped: “$#”" % Str2.removeComments(';')</lang>


{{out}}
echo removeComments("apples, pears # and bananas", '#')
<pre>Original: “apples, pears # and bananas”
echo removeComments("apples, pears ; and bananas", ';')</lang>
Stripped: “apples, pears”
Original: “apples, pears ; and bananas”
Stripped: “apples, pears”</pre>


=={{header|Objeck}}==
=={{header|Objeck}}==