RosettaCodeData/Task/Strip-comments-from-a-string/Nim/strip-comments-from-a-string.nim

14 lines
374 B
Nim
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
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(';')