If you just echo the string s on it's own you will see you get the same output. This is because you have various control sequences in the string which command the terminal to do something other than print a character.
The \r in the string causes a carriage return, meaning the terminal will move the cursor to the beginning of the line and any subsequent prints to the terminal will overwrite the cells.
The \c does the same as \r.
The \l is also telling the terminal to move to the next line which makes it look like a newline between baz and end.
This code will print your string a character every second and demonstrate what I mean:
import os
var s = "foo\rbar\cbaz\lend"
for c in s:
stdout.write(c)
stdout.flushFile()
os.sleep(1000)
@masiarek2, what @GamzWithJamz is saying is that your string has control characters in it, and indeed no split is occuring, you just have some carriage returns and a newline in your string. You can see that split does nothing by doing this:
import strutils
var s = "foo\rbar\cbaz\lend"
echo s
echo s.split({';'})[0]
# Outputs
baz
end
baz
end
So you can see, no splitting occurs. What you want is probably this:
import strutils
var s = r"foo\rbar\cbaz\lend" # notice the "r" in front of the string
for e in split(s, {';'}):
echo e
# Outputs
foo\rbar\cbaz\lend
He could also instead echo e.repr to see that it is only one string (only one address prints). When I did this I got:
0x14ec252cc090"foo\13bar\13baz\10"
"end"
which kinda looks like maybe a bug in repr..I mean it quotes the newline as "10", but then puts one there anyway. Not sure. I don't use repr like this often.include prelude
var s = "foo\rbar\cbaz\lend"
for e in split(s, {';'}):
echo e
echo e.repr
echo (e,)
nim r main
baz
end
0x10a6ce090"foo\13bar\13baz\10"
"end"
("foo\rbar\rbaz\nend",)
nim r --gc:arc main
baz
end
"foo\13bar\13baz\n
end"
("foo\rbar\rbaz\nend",)