2017-08-01 80 views
0

所以我有一點機管局發行除去撇號之一....串2個單引號 - 從字符串

我有一個字符串,它看起來像這樣...

O''Neil 

有一種方法來刪除一個撇號?基本上,我想將其轉換回

O'Neil 
+0

你並不需要更改數據,如果你使用的參數 – Plutonix

+0

@Plutonix - 我知道,但我們不使用PARAMS :( – BobSki

+1

...但是這僅僅是30倍或40的原因之一,爲什麼你 – Plutonix

回答

1

希望這可以幫助你: 注意 - 我離開了錯誤處理給你。

Imports System 

Public Module Module1 
    Public Sub Main() 

     Dim data As String = "O''Neil" 

     Dim in1 As Integer = data.IndexOf("'"C) ' get the index of first quote 
     Dim in2 As Integer = data.IndexOf("'"C, in1 + 1) ' get the index of second  
     Dim result As String = data.Remove(in2, 1) ' remove the second quote 

     Console.WriteLine(result) 
    End Sub 
End Module 
+3

此代碼將拋出一個異常,如果沒有沒有兩個單引號,並且還有一個內置的.net函數String.Replace(),它將整個子邏輯合併爲一個不會拋出異常的單個調用如果沒有找到2個單引號。爲什麼重新發明輪子? – soohoonigan