Sub AppStart (Args() As String)
Dim s As String = $"10.8+
3+
5"$
Dim m As Matcher = Regex.Matcher2("^([\d\.]+)", Regex.MULTILINE, s)
Do While m.Find
Log(m.Match)
Loop
End Sub
I solved it with integration of the hand sign. It is used to calculate the multiple discount in the management systems: 10 + 4 + 5.
thank
Regex:
Dim m As Matcher = Regex.Matcher2("[\d\.]+", Regex.MULTILINE, strFormula)
Dim aSegno As String
Do While m.Find
Dim aPos As Int = strFormula.IndexOf(m.Match)
If aPos = 1 Then
aSegno = strFormula.CharAt(0)
Else
Dim aStart As Int = aPos -1
Dim aLun As Int = m.Match.Length
aSegno = strFormula.SubString2(aStart, aLun+aStart)
End If
If aSegno = T_PLUS Then
dDebitCreditSign = 1.0
else if aSegno = T_MINUS Then
dDebitCreditSign = -1.0
End If
If Not(bIsFirstDiscount) And dFromToDiscount = 100.00 Then
dFromToDiscount = dFromToDiscount - aData.mPerc1
End If
...
loop
The attached class allows you to evaluate mathematical expressions with support for custom functions. It is compatible with B4A, B4J and B4i. Example: Sub AppStart (Args() As String) Dim e As B4XEval e.Initialize(Me, "Eval") Log(e.Eval("1 + Min(2, Max(-4, 1), 6)"))...
The attached class allows you to evaluate mathematical expressions with support for custom functions. It is compatible with B4A, B4J and B4i. Example: Sub AppStart (Args() As String) Dim e As B4XEval e.Initialize(Me, "Eval") Log(e.Eval("1 + Min(2, Max(-4, 1), 6)"))...
Dim S As String ="10+3+7-11.5+26"
Dim Lines() As String = Regex.Split("\+|\-", S)
Dim values(6) As String
Dim t As Int
Dim i As Int
Log(S)
Log("")
For Each Line As String In Lines
t=S.IndexOf(Line)
If t>0 Then
If S.CharAt(t-1)="-" Then
values(i)="-" & Line
Else
values(i)=Line
End If
Else
values(i)=Line
End If
Log(values(i))
i=i+1
Next
Output (s):
Waiting for debugger to connect...
Program started.
10+3+7-11.5+26
10
3
7
-11.5
26
Waiting for debugger to connect...
Program started.
10+3-7.02-11.5+26.5
10
3
-7.02
-11.5
26.5
Waiting for debugger to connect...
Program started.
-9.8+3-7.02-11.5+26.5
-9.8
3
-7.02
-11.5
26.5
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.