strsplit behavior

kolbe

Active Member
Licensed User
Longtime User
I need to split a string that contains multiples lines into an array where each array element contains one line. Using array()=strsplit(source_string,&crlf) gives me an array with extra lines between each original line.

So if the original string was


the array gets filled like this

array(0)="1"
array(1)=&crlf
array(2)="2"
array(3)=&crlf
array(4)="3"
array(5)=&crlf

I see similar &crlf "inserted" behavior if the separator string is more than one character.

Is this normal behavior? Being how the &crlf is the separator I won't expect them to be part of the result.

This can be worked around but thought I'd ask if others see the same behavior.
 

specci48

Well-Known Member
Licensed User
Longtime User
Hi kolbe,

the problem may be that CRLF is a combination of "carriage return" and "line feed".
As a workaround you can remove one part of these within the origininal string before splitting it into an array:
B4X:
' remove all "line feed" within the original string
tempString = StrReplace(originalString, Chr(13))
' split into array by "carriage return"
a() = StrSplit(tempString, Chr(10))


specci48
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…