- Home
·
- String Manipulation
·
- this code implements the REPLACE function in VB5 or lower, which comes in VB6. It is the exact impl
this code implements the REPLACE function in VB5 or lower, which comes in VB6. It is the exact impl
this code implements the REPLACE function in VB5 or lower, which comes in VB6. It is the exact implementation and works similar to the details
Rate this code implements the REPLACE function in VB5 or lower, which comes in VB6. It is the exact impl
(1(1 Vote))
'Author: Prashant Sharma
'Web-site: http://www.prashantsharma/com
'eMail: [email protected]
'Copy and paste this function in a module
Public Function Replace(ByVal sExp As String, ByVal sFind As String, ByVal sReplace As String, Optional ByVal lStart As Long = 1, Optional ByVal lCount As Long = -1, Optional ByVal Compare As VbCompareMethod = vbBinaryCompare) As String
Dim i As Long, j As Long, idx As Long, fl As Long, rl As Long
idx = 0
fl = Len(sFind)
rl = Len(sReplace)
i = lStart
j = InStr(i, sExp, sFind, Compare)
'Loop only if needed
Do While j > 0
If idx = lCount Then Exit Do
sExp = Left$(sExp, j - 1) & sReplace & Mid$(sExp, j + fl)
idx = idx + 1
i = j + rl
j = InStr(i, sExp, sFind, Compare)
Loop
Replace$ = sExp
End Function
'The sample usage is given here, copy and paste it in a form...
Private Sub Form_Load()
Dim sSrc As String, sDst As String, sFind As String, sRepl As String
sSrc = "This is a test"
sFind = "a"
sRepl = "NOT"
sDst = Replace(sSrc, sFind, sRepl)
MsgBox sDst
End Sub
this code implements the REPLACE function in VB5 or lower, which comes in VB6. It is the exact impl Comments
No comments yet — be the first to post one!
Post a Comment