How to extract a value from a string?

sktanmoy

Active Member
Licensed User
Longtime User
A string example: Dear Example Name, you've received $140 from [email protected]. Transaction ID is UFIR-12324 and current balance is $220. Thanks"

So how can I extract amount, email, transaction and balance from this string?:sign0104:
 

mangojack

Expert
Licensed User
Longtime User
This will do the job and there might be a better method .The string statement would obviously have to be consistent for this to work.
You would also have to watch duplicate words within statement.

B4X:
Dim MyText,sAmount,sEmail ,sID, sBalance As String
Dim start,stop As Int

MyText = "Dear Example Name, you've received $140 from [email protected]. Transaction ID is UFIR-12324 and current balance is $220. Thanks"

start = MyText.IndexOf("received")
stop = MyText.IndexOf("from")
sAmount = MyText.SubString2(start +9,stop -1)

start = MyText.IndexOf("from")
stop = MyText.IndexOf("Trans")
sEmail = MyText.substring2(start +5,stop -1)

start = MyText.IndexOf("ID")
stop = MyText.IndexOf("and curr")
sID = MyText.substring2(start +6,stop -1)

start = MyText.IndexOf("balance")
stop = MyText.IndexOf("Thanks")
sBalance = MyText.substring2(start +11,stop -2)

Msgbox(sAmount & "     " & sEmail & "      " & sID & "      " & sBalance,"Individual Strings ...")

Cheers mj
 
Last edited:
Upvote 0
Top