我使用 Visual Basic 2010。我让用户输入一个字符串、好的子字符串和坏的子字符串(三个文本框)。我需要让我的代码在我的字符串中找到坏子字符串的实例,并用好的子字符串替换每个实例。我觉得应该有一个循环来确定坏子字符串的实例。我就是想不通。这是我到目前为止所拥有的一切。希望有人可以帮助我。
Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
Dim strEnteredString As String = txtInputString.Text.Trim
Dim intEnteredStringChars As Integer = strEnteredString.Length
Dim strGoodSubstring As String = txtInputGoodString.Text.Trim
Dim intGoodSubstringChars As Integer = strGoodSubstring.Length
Dim strBadSubstring As String = txtInputBadString.Text.Trim
Dim intBadSubstringChars As Integer = strBadSubstring.Length
Dim strNewString As String = strEnteredString
Dim strNewStringFinal As String
If strEnteredString.Contains(strBadSubstring) Then
strNewStringFinal = strNewString.Remove(
strNewString = strEnteredString.Insert(intBadSubstringChars, strGoodSubstring)
End If