Reputation: 1830
I have an string like this:
Dim value as string = "hy the number is (30.01)"
How i can get this number 30.01 into another variable?
I am thinking to use split
, How i can use to get this value thanks
Upvotes: 1
Views: 3041
Reputation: 2782
Use regular expressions (System.Text.RegularExpressions):
Dim m As Match = Regex.Match(value, "\((?<n>\d+\.\d{2})\)")
If m.Success Then
Dim n As Decimal = Decimal.Parse(m.Groups("n").Value)
End If
Upvotes: 4
Reputation: 54532
If your format is going to be exactly the same, you can try using Split like you mentioned. This can be very fragile if anything changes.
See if this works for you.
Dim result As Double
Dim value As String = "hy the number is (30.01)"
Dim subValue() As String = value.Split("(")
subValue(1) = subValue(1).TrimEnd(")")
If Not Double.TryParse(subValue(1), result) Then
'Error handling code here
End If
Upvotes: 3