|
Visual Basic (VB and VBA) |
|
Copyright 1999-2001 Christopher Greaves. All rights reserved. Home Page and email to [email protected] |
| If in doubt, record a macro and inspect the entrails! |
Please read the DISCLAIMER.
Here is an INDEX to all the procedures.
You will probably need one copy of my GLOBAL DECLARATIONS.
'Public Function strReplaceAll(ByVal strSource As String, strFind As String, strReplace As String)
'' Procedure : strReplaceAll
'' Description: Return the string with replacement effected.
'' Copyright: Chris Greaves Inc.
'' Inputs: A string, a FIND string, a REPLACE string.
'' Returns: A sub-string of the original string.
'' Assumes: None.
'' Side Effects: None.
'' Tested: By the calls shown below.
'' Posted in Woody's Lounge VBA forum
' Dim intI As Integer
' Dim intOldI As Integer
' intI = InStr(1, strSource, strFind)
' While intOldI < intI
' intOldI = intI
' strSource = Left(strSource, intI - 1) & strReplace & Right(strSource, Len(strSource) - intI - Len(strFind) + 1)
' intOldI = intI
' intI = InStr(intOldI + 1, strSource, strFind)
' Wend
' strReplaceAll = strSource
''Sub TESTstrReplaceAll()
''MsgBox strReplaceAll("abc^^^^def", "^^", "^")
'''MsgBox strReplaceAll(" here is a sample string ", " ", " ")
''End Sub
'End Function
Public Function strReplaceAll(ByVal strSource As String, strFind As String, strReplace As String)
' Procedure : strReplaceAll
' Description: Return the string with replacement effected.
' Copyright: Chris Greaves Inc.
' Inputs: A string, a FIND string, a REPLACE string.
' Returns: A sub-string of the original string.
' Assumes: None.
' Side Effects: None.
' Tested: By the calls shown below.
' Posted in Woody's Lounge VBA forum
Dim intI As Integer
Dim intOldI As Integer
intI = InStr(1, strSource, strFind)
While intOldI < intI
intOldI = intI
strSource = Left(strSource, intI - 1) & strReplace & Right(strSource, Len(strSource) - intI - Len(strFind) + 1)
intOldI = intI
intI = InStr(intOldI + Len(strReplace), strSource, strFind)
Wend
strReplaceAll = strSource
'Sub TESTstrReplaceAll()
'MsgBox strReplaceAll("d:\greaves\products\", "\", "\\")
''MsgBox strReplaceAll(" here is a sample string ", " ", " ")
'End Sub
End Function
| We all knew nothing when we started … |
|
Home Page and Contact Information Send email to [email protected]. This page was last updated Thursday, November 15, 2001 |