Hello Experts !
i am making a case in which user can create custom formula by selecting multiple strings,
Now, when user saves the formula, it is in this form
Quote:
(AL01-RM)+(AL03-RM)+20.0
inside brackets Strings are some ids of the elements (that are in datagridview column),
now the scenario is,
1- it gets the above string,
2- find string inside brackets () in datagridview column by Regex pattern "(?<=\().*?(?=\))")
3- if string insides brackets() matches with datagridview column 1 value,
4- now get the value from datagridview column 2 (that is the value of string)
5- now replace value in first input string inside brackets() , and here is i have stuck,
i want string like this
"(10)+(30)+20"
but i get string like this
"(10 )+(AL03-RM)+20.0(AL01-RM)+(30)+20.0"
i have tried different things, but can't get out put like
"(10)+(30)+20"
Please see image for details
Imgur: Image Link for Details[
^]
Please help me to solve this.
What I have tried:
Private Sub SimpleButton2_Click(sender As Object, e As EventArgs) Handles SimpleButton2.Click
For i As Integer = 0 To dgv.Rows.Count - 1
'Dim paren As New Regex("\([^)]*\)")
'Dim paren As New Regex("\((.*?)\)")
Dim paren As New Regex("(?<=\().*?(?=\))")
Dim command As String = "((AL01-RM)+(AL03-RM))+20.0"
Dim matches As MatchCollection
matches = paren.Matches(command)
Dim m As Match
For Each m In matches
If m.ToString = dgv.Rows(i).Cells(1).Value Then
RTB2.AppendText(Regex.Replace(command, m.ToString, dgv.Rows(i).Cells(2).Value.ToString))
End If
Next
Next
End Sub