样品:
字符串:George (Babe) Ruth
(计算) - 输出:
George Ruth
我将如何在VB中解决这个问题?
答案 0 :(得分:2)
您可以使用Regex并执行此操作
ResultString = Regex.Replace(SubjectString, "\\(.+\\)", "");
答案 1 :(得分:0)
它应该可以正常工作,因为你的标签是VB.net.if不是上面的Regex也适用
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)
答案 2 :(得分:0)
捎带用户2526236的答案......
使用VB.net使用此函数 - 使用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