SyntaxBomb - Indie Coders

Languages & Coding => Monkey => Topic started by: jvdw007 on March 28, 2019, 21:58:44

Title: Anyone know how to split a string by line break?
Post by: jvdw007 on March 28, 2019, 21:58:44
As the title says, I'm trying to split a long string from a csv file by the line breaks.
Looked at the example banana files and the older monkey docs but not finding anything that says how to use special chars like line breaks.
Tried thestring.split("\r\n"), thestring.split(chr(10)) (and other variants like chr$(10) char$(10) etc and none work.

If this is not possible, maybe I can read the file in line-by-line instead I guess?

Thanks,
Jaco
Title: Re: Anyone know how to split a string by line break?
Post by: Derron on March 28, 2019, 22:32:32
There is not just "\r\n" - maybe have a closer look in Notepad++ (or so) and let you display line endings so you see if it is CR/LF or just LF or ...

In BlitzMax the newline char is escaped as "~n" - assume this is the same in Monkey-X/Cerberus.


bye
Ron
Title: Re: Anyone know how to split a string by line break?
Post by: jvdw007 on March 28, 2019, 22:46:36
Hey Ron,

Thanks a load for that. I never used blitzmax so wasn't aware. Saying that, I tried it and it worked! Happy days!  ^-^
Title: Re: Anyone know how to split a string by line break?
Post by: GW on March 29, 2019, 23:19:43
I usually first try:  String.Replace("~r","").Split("~n")
Title: Re: Anyone know how to split a string by line break?
Post by: jvdw007 on March 29, 2019, 23:35:47
Thanks for the tip GW!