2017-01-10 91 views

回答

0
Dim findWhat As String = "ee" 
    Dim searchThis As String = "need" 
    Dim replaceWith As String = "o" 
    Dim result As String = searchThis.Replace(findWhat, replaceWith & findWhat.Substring(1)) 
    Console.WriteLine(result) 
1

使用IndexOf()找到“e”的位置。现在Insert()该位置的“o”和Remove()紧随其后的位置去掉“e”的位置:

Dim word As String = "need" 
    Dim oldLetter As String = "e" 
    Dim newLetter As String = "o" 
    Dim index As Integer = word.IndexOf(oldLetter) 
    If index <> -1 Then 
     word = word.Insert(index, newLetter).Remove(index + 1, 1) 
    End If 
相关问题