search in string

salmander

Active Member
Licensed User
Longtime User
Hi all,

I am getting a string which has "_" (under-scores) as line separator.
How can I fine the underscore in a string and make a new string.
In order to explain it better, here is the example;
string = "this is a first line_this is a second line_this is third"
i want to separate this string into;
string1 = "this is a first line"
string2 = "this is a second line"
string3 = "this is third line"

And also the number of lines is unknown as its a dynamically generated string.
Please help

Thanks
 

kickaha

Well-Known Member
Licensed User
Longtime User
Regex is what you need
B4X:
Dim data As String
data = "this is a first line_this is a second line_this is third"
Dim lines() As String
lines = Regex.Split("_", data)
lines(0) will be "this is a first line"
lines(1)will be "this is a second line"
lines(2) will be"this is third"

Check this link
 
Upvote 0

salmander

Active Member
Licensed User
Longtime User
Regex is what you need
B4X:
Dim data As String
data = "this is a first line_this is a second line_this is third"
Dim lines() As String
lines = Regex.Split("_", data)
lines(0) will be "this is a first line"
lines(1)will be "this is a second line"
lines(2) will be"this is third"

Check this link
Thank you so much...it works perfectly. :)
 
Upvote 0
Top