自己编写了一个VB.Net的Replace方法,与大家分享!若有更好的方法,我们可以一起讨论!
Public
Function Replace(ByVal strSource As String, ByVal oldStr As String, ByVal newStr As String) As String

Dim idxSearch As Integer
Dim isExist As Boolean = False
Dim strReturn As String = ""

For i As Integer = 0 To strSource.Length - 1
If AscW(strSource.Chars(i)) = AscW(oldStr.Chars(0)) Then
'找到匹配要替换的第一个字符
isExist = True
For j As Integer = 0 To oldStr.Length - 1
'继续查找是否存在此oldStr
If AscW(oldStr.Chars(j)) <> AscW(strSource.Chars(i + j)) Then
isExist = False
Exit For
End If
Next j

If isExist Then
'若strSource存在oldStr,则将newStr接在strReturn后面
For k As Integer = 0 To newStr.Length - 1
strReturn &= newStr.Chars(k)
Next
Else
strReturn &= strSource.Chars(i)
End If

Else
strReturn &= strSource.Chars(i)
End If
Next i

Return strReturn

End Function


































