我只需要知道如何用不同的字符替换出现在字符串中的第一个特定字符。
例如,我需要能够改变"需要"到" noed"留下第二个'相同。
我现在所拥有的是改变"需要"到" nood"
如果您需要任何澄清,请问我!非常感谢你!
答案 0 :(得分: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
答案 1 :(得分: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)