2017-01-10 9 views
1

文字列内に表示される最初の特定の文字を別の文字に置き換える方法を知っておくだけでいいです。文字列内の最初の特定の文字を置き換える方法2番目の文字をそのまま残す方法

たとえば、「need」を「noed」に変更して、2番目の「e」を同じままにする必要があります。私は今、「nood」に「必要性」に変更されている何

何か明確化が必要な場合はちょうど私に聞いてください!どうもありがとうございます!

答えて

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

「e」の位置を見つけるのに、IndexOf()を使用してください。今すぐInsert()その位置の "o"と "e"を取り除くための直後の位置Remove()

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 
関連する問題