Split text on two parts

vdudukov

Member
Licensed User
Longtime User
Hi

I have a text which I am receiving from my bluetooth scale. Text is in this format.


$number1#number2*

What i want is "number1" in one textbox, and "number2" in second textbox.

I did not found answer, so if somebody can help.

Thank you.
 

Theera

Expert
Licensed User
Longtime User
Hi

I have a text which I am receiving from my bluetooth scale. Text is in this format.


$number1#number2*

What i want is "number1" in one textbox, and "number2" in second textbox.

I did not found answer, so if somebody can help.

Thank you.

Hi vdudukov,
You could use Magret's StringFunction to solve this problem.
 
Upvote 0

Theera

Expert
Licensed User
Longtime User
Excellent coding :)
 
Upvote 0

vdudukov

Member
Licensed User
Longtime User
Here:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim s As String = "$number1#number2*"
   Dim m As Matcher = Regex.Matcher("\$([^#]+)#([^*]+)\*", s)
   If m.Find Then
      Log(m.Group(1))
      Log(m.Group(2))
   End If
End Sub

Hey can I borrow Your brain, just for a few days :)

Thank You very much.

I did some coding, but it has a few bugs. This code is Perfect:)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Regular expressions look awfully complicated until you look close enough...
B4X:
"\$([^#]+)#([^*]+)\*"

I will explain the pattern here:
- $ is a special character so we need to "escape" it -> \$
- Then we want to catch all characters that are not # -> ([^#]+) note that the parenthesis define a group (group number 1).
- The # character.
- All characters that are not * -> ([^*]+) note that we do not need to escape special characters in a negation class.
- The * character.
 
Upvote 0

vdudukov

Member
Licensed User
Longtime User
Regular expressions look awfully complicated until you look close enough...
B4X:
"\$([^#]+)#([^*]+)\*"

I will explain the pattern here:
- $ is a special character so we need to "escape" it -> \$
- Then we want to catch all characters that are not # -> ([^#]+) note that the parenthesis define a group (group number 1).
- The # character.
- All characters that are not * -> ([^*]+) note that we do not need to escape special characters in a negation class.
- The * character.


When I put this code, everything is working OK, except application slows down. I dont know where is the problem.
 
Upvote 0

vdudukov

Member
Licensed User
Longtime User
How many times are you calling it? Can you post your code?

Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
Serial1.Initialize("Serial1")
Timer1.Initialize("Timer1", 200)
End If
End Sub

Sub
Timer1_Tick
Dim s As String
Dim m As Matcher

s = TextReader1.ReadLine
txtLog.Text = s
m = Regex.Matcher("\$([^#]+)#([^*]+)\*", s)
If m.Find Then
Label1.Text=(m.Group(1))
Label2.Text=(m.Group(2))
End If
End Sub

Ok. Now I put timer to 400 and it is ok.

But just one question please.

When i minimize application, after maybe 30 seconds or 1 minute I go back to application, numbers are late. i Think the problem is with buffer?
 
Last edited:
Upvote 0
Top