hmm ik zal even kijken het moet blijkbaar toch kunnen ...
dit is wat ik dacht :
[CPP]''string in textbox
'' split string like : (546, *, 3, -, (,2, /, 5,),)
'' detect () somehow and put apart
'' detect if number or operator
'' calculate (2/5) using operators as operators = as preint
''calculate integer = 546 * 3 - preint..
''result = 1637,6
[/CPP]
ik heb dit gevonden het werkt!
nu even goed studeren hoe...
[CPP] Public Function RefactoredCalculateInput(ByVal input As String) As String
''start by trimming the input
Dim inputSum As String = input.Replace(" ", "")
While inputSum.Contains("*")
Dim operatorIndex As Integer = inputSum.IndexOf("*"c)
Dim replaceStartIndex As Integer = 0
For i As Integer = operatorIndex - 1 To 0 Step -1
If IsOperator(inputSum.Substring(i, 1)) Then
replaceStartIndex = i + 1
Exit For
End If
Next
Dim secondlength As Integer = inputSum.Length - (operatorIndex + 1)
For i As Integer = operatorIndex + 1 To inputSum.Length - 1
If IsOperator(inputSum.Substring(i, 1)) Then
secondlength = i - (operatorIndex + 1)
Exit For
End If
Next
Dim replaceLength As Integer = secondlength + 1 + (operatorIndex - replaceStartIndex)
Dim x As Integer = Convert.ToInt32(inputSum.Substring(replaceStartIndex, Math.Max(1, operatorIndex - replaceStartIndex)))
Dim y As Integer = Convert.ToInt32(inputSum.Substring(operatorIndex + 1, secondlength))
inputSum = inputSum.Replace(inputSum.Substring(replaceStartIndex, replaceLength), (x * y).ToString())
End While
Return inputSum
End Function
[/CPP]
vrij lastig.. iemand die dit goed begrijpt wat er gebeurt?
ik heb de code voor mezelf wat simpeler gemaakt door zo veel mogelijk er uit te gooien:
edit : OEPS nu doet die geen meervoudige berekeningen meer

[CPP]
Dim inputSum As String = input.Replace(" ", "")
''multiply
While inputSum.Contains("*") ''check for multi operator
Dim operatorIndex As Integer = inputSum.IndexOf("*"c) '' dim location of the operator. as integer and look for * as an char not as string
Dim replaceStartIndex As Integer = 0
Dim secondlength As Integer = inputSum.Length - (operatorIndex + 1)
Dim replaceLength As Integer = secondlength + 1 + (operatorIndex - replaceStartIndex)
Dim x As Integer = Convert.ToInt32(inputSum.Substring(replaceStartIndex, Math.Max(1, operatorIndex - replaceStartIndex))) ''convert found numbers into intgers
Dim y As Integer = Convert.ToInt32(inputSum.Substring(operatorIndex + 1, secondlength))
inputSum = inputSum.Replace(inputSum.Substring(replaceStartIndex, replaceLength), (x * y).ToString()) ''calculate sum
End While
Return inputSum '' returns made sum to textb
[/CPP]
nu nog met haakjes werken..