Android Question Need help with SMS

apty

Active Member
Licensed User
Longtime User
I am new to basic4android, just bought it today :). I need help formating SMS. The sms comes from a specific source e.g. DAILY ALERTS and is in the following format.
QNBX CONFIRMED. You have received USD 45 from abx nyd 458236 on 9/4/14 at 10:10 AMNEW Balance is USD 340.

I want the message to appear as below
ITEMNO AMOUNT USER NUMBER DATETIME BALANCE
QNBX USD 45 abx nyd 458236 9/4/14 10:10AM USD 340

Is this possible with B4a? I want to pick the message immediately it is received and store it in sqlite database. Then display it as above. Kindly help on how i can achieve this. Thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

apty

Active Member
Licensed User
Longtime User
Thanks Erel. I have tried using the pattern you have indicated on the tool but it just returns me to initial screen (i.e no changes on output) when i click parse.
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
Works for me but not in firefox. Chrome is okay. No socket in Firefox!
 

Attachments

  • regex.jpg
    regex.jpg
    82.1 KB · Views: 126
Upvote 0

apty

Active Member
Licensed User
Longtime User
Hi Erel,
How did you get the above regex pattern. I am unable to generate patterns using a different string..please tell me what the w,s or d stands for in the pattern
 
Upvote 0

apty

Active Member
Licensed User
Longtime User
i got the pattern correct (using the online tool) but when i copy the same to basic4android, it doesn't give me any results..just a blank listview
B4X:
smsbody=Sms1.Body
        smsaddress=Sms1.Address
        If smsbody.Contains("received") Then
        Dim matcher1 As Matcher
matcher1 = Regex.Matcher("(\w+).*received usd(\S+) from(\S+) (\S+) (\S+)on (\S+) at (\S+) (\S+)New balance is usd(\S+).xxx", smsbody)
If matcher1.Find = True Then
  ' Log(matcher1.Match)
  Dim receiptno, firstname,lastname,phoneno,date,time,time2,strdate As String
  Dim amount,Balance As Int
        receiptno = matcher1.Group(1) 'fetch the first captured group.
        amount = matcher1.Group(2)
        ListView1.AddSingleLine (receiptno)
        ListView1.AddSingleLine(smsaddress)
This gives me blank listview, but it works if i dont use the regex function. What am i doing wrong?
 
Upvote 0

apty

Active Member
Licensed User
Longtime User
the content is
B4X:
bxd Confirmation. You have received usd50.00 fromHulk Juin xyzcc on 9/4/14 at 10:53 AMNew balance is usd50.00.xxx
 
Upvote 0

mitobobo

Member
Licensed User
Longtime User
B4X:
Dim m As Matcher = Regex.Matcher("(\w+) .* received (\S+) (\d+) from (\S+) (\S+) (\S+) on (\S+) at (\S+) (\w\w)NEW Balance is (\S+) (\S+)", smsbody)
If matcher1.Find = True Then
receiptno = Matcher.Group(1)
amount = Matcher.Group(2)
End If

QNBX CONFIRMED. You have received USD 45 from abx nyd 458236 on 9/4/14 at 10:10 AMNEW Balance is USD 340.

What does "xxx" stand for? Currency(EUR, USD, ...)?
 
Upvote 0
Top