Reputation: 90
Sample:
The string: George (Babe) Ruth
(calculate) - output:
George Ruth
How would I go about this in VB?
Upvotes: 1
Views: 4581
Reputation: 296
To piggyback on user2526236's answer....
With VB.net use this function - pass in the string with the parens...
Private Function RemoveChunk(psString As String) As String
Dim iStart As Integer
Dim iStop As Integer
Dim sModifiedString As String
iStart = InStr(psString, "(")
iStop = InStr(psString, ")")
If iStart > 0 And iStop > 0 Then
sModifiedString = psString.Remove(iStart - 1, iStop + 1 - iStart)
Else
'nothing to modify
sModifiedString = psString
End If
Return sModifiedString
End Function
Upvotes: 0
Reputation: 1538
It should work as your tag was VB.net.if not the above Regex also works
Dim s2,s,d,g as string
s2 = "George (Babe) Ruth "
s = InStr(1, s2, " (")
d = InStr(1, s2, ") ")
g = s2.Remove(s, d + 1 - s)
Upvotes: 0
Reputation: 6480
You can use Regex and do this
ResultString = Regex.Replace(SubjectString, "\\(.+\\)", "");
Upvotes: 2