VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



A String Replacement Function

by MilkTin (1 Submission)
Category: String Manipulation
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (10 Votes)

I know there is the
replace(text1.text,"Jack","Jill")
in VB6 which would find all the words Jack and replace them with Jill in text1, but how can I do this in VB5?
I want to be able to put symbols in general sentences, and replace the symbols with specific data. such as:
Thats a great pass from #!
He passes to # who sets up a shot!

Rate A String Replacement Function

'Explainaion - http://go.to/cyberprogrammer
Private Sub cmdReplace_Click()
 Text1.Text = pReplace(Text1.Text, txtFind, txtReplace)
End Sub

Public Function pReplace(strExpression As String, strFind As String, strReplace As String)
 Dim intX As Integer
 If (Len(strExpression) - Len(strFind)) >= 0 Then
  For intX = 1 To Len(strExpression)
    If Mid(strExpression, intX, Len(strFind)) = strFind Then
      strExpression = Left(strExpression, (intX - 1)) + strReplace + Mid(strExpression, intX + Len(strFind), Len(strExpression))
    End If
  Next
 End If
 pReplace = strExpression
End Function

Download this snippet    Add to My Saved Code

A String Replacement Function Comments

No comments have been posted about A String Replacement Function. Why not be the first to post a comment about A String Replacement Function.

Post your comment

Subject:
Message:
0/1000 characters