2013-11-26 47 views

回答

2

您可以使用正則表達式,併爲此

ResultString = Regex.Replace(SubjectString, "\\(.+\\)", ""); 
+0

標題中說他想刪除parens,但是該示例顯示他想要替換其中的文本: George(Babe)Ruth' ==>'George Ruth'這意味着吃太空 – Plutonix

+0

嗯沒有注意到,將等待OP更新 – Pepe

+0

是的,這是真的,我需要刪除括號內的內容 –

0

它應該爲你的標籤是不VB.net.if上述正則表達式也適用

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) 
0

捎帶上user2526236的答案.. ..

使用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 
相關問題