.Net Replacement for PHP’s str_replace

Here is a quick and dirty function that I grabbed from ( http://support.microsoft.com/kb/251354/ ). It does a nice job of replacing PHP’s convenient str_replace.

Private Function str_replace(ByVal strSource As String, _
ByVal strSearchFor As String, ByVal strReplace As String) As String
Dim lngPointer As Long, strNew As String
lngPointer = InStr(strSource, strSearchFor)
If lngPointer = 0 Then
ReplaceEntXMLSpecChar = strSource
Else
strNew = Left$(strSource, lngPointer - 1) & strReplace _
& Mid(strSource, lngPointer + 1, Len(strSource))
ReplaceEntXMLSpecChar = strNew
End If
End Function

1 Comment


  1. You can also just use Replace(string, replace, find)

    Quote | PostedJune 30, 2007, 3:50 pm

Leave a reply