Sub AppStart(Args() As String)
Dim s As String = $"10.8+
3+
5"$Dim m As Matcher = Regex.Matcher2("^([\d\.]+)", Regex.MULTILINE, s)
DoWhile m.Find
Log(m.Match)
LoopEndSub
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 StringDoWhile m.Find
Dim aPos As Int = strFormula.IndexOf(m.Match)
If aPos = 1Then
aSegno = strFormula.CharAt(0)
ElseDim aStart As Int = aPos -1Dim aLun As Int = m.Match.Length
aSegno = strFormula.SubString2(aStart, aLun+aStart)
EndIfIf aSegno = T_PLUS Then
dDebitCreditSign = 1.0elseif aSegno = T_MINUS Then
dDebitCreditSign = -1.0EndIfIfNot(bIsFirstDiscount) And dFromToDiscount = 100.00Then
dFromToDiscount = dFromToDiscount - aData.mPerc1
EndIf
...
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 StringDim t As IntDim i As IntLog(S)
Log("")
ForEach Line As StringIn Lines
t=S.IndexOf(Line)
If t>0ThenIf S.CharAt(t-1)="-"Then
values(i)="-" & Line
Else
values(i)=Line
EndIfElse
values(i)=Line
EndIfLog(values(i))
i=i+1Next
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.