Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Visual Basic Programming Code Examples

Visual Basic > Strings Code Examples

Simple Replace function

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
Simple Replace function Public Function Replace(ByVal WorkingString As String, _ ByVal OldText As String, Optional _ ByVal NewText As String = "") As String 'Dimension any variables. Dim I As Long 'Loop through string doing any replacements. For I = Len(WorkingString) To 1 Step -1 If Mid$(WorkingString, I, Len(OldText)) = OldText Then WorkingString = Left$(WorkingString, I - 1) _ & NewText & Right$(WorkingString, _ Len(WorkingString) - (I - 1 + Len(OldText))) I = I - Len(NewText) + 1 End If DoEvents Next Replace = WorkingString End Function