RosettaCodeData/Task/Strip-comments-from-a-string/Nim/strip-comments-from-a-string.nim
2023-07-01 13:44:08 -04:00

13 lines
374 B
Nim

import strutils
proc removeComments(line: string; sep: char): string =
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(';')