August 23, 2019, 06:19:40 PM

Author Topic: Anyone know how to split a string by line break?  (Read 709 times)

Offline jvdw007

  • Jr. Member
  • **
  • Posts: 27
    • Blackjet Games
Anyone know how to split a string by line break?
« on: March 28, 2019, 09:58:44 PM »
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
Retro gaming fan and maker sometimes...

Offline Derron

  • Hero Member
  • *****
  • Posts: 2337
Re: Anyone know how to split a string by line break?
« Reply #1 on: March 28, 2019, 10:32:32 PM »
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

Offline jvdw007

  • Jr. Member
  • **
  • Posts: 27
    • Blackjet Games
Re: Anyone know how to split a string by line break?
« Reply #2 on: March 28, 2019, 10:46:36 PM »
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!  ^-^
Retro gaming fan and maker sometimes...

Offline GW

  • Full Member
  • ***
  • Posts: 169
Re: Anyone know how to split a string by line break?
« Reply #3 on: March 29, 2019, 11:19:43 PM »
I usually first try:  String.Replace("~r","").Split("~n")

Offline jvdw007

  • Jr. Member
  • **
  • Posts: 27
    • Blackjet Games
Re: Anyone know how to split a string by line break?
« Reply #4 on: March 29, 2019, 11:35:47 PM »
Thanks for the tip GW!
Retro gaming fan and maker sometimes...