2017-08-01 64 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