如何替换字符串中的第一个特定字符,使第二个字符保持不变



我只需要知道如何用不同的字符替换字符串中出现的第一个特定字符。

例如,我需要能够将"需要"更改为"点头",使第二个"e"保持不变。

我现在所拥有的是将"需要"改为"点头"

如果您需要任何澄清,请问我!非常感谢!

使用 IndexOf() 查找 "e" 的位置。 现在在该位置插入 "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
    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)