'********************************************************************

'*

'* Function LReplace

'*

'*   Author: NetworkAdminKB.com

'*  Created: 2007-01-24

'* Modified: 2008-12-06

'*

'* Purpose: From the left side of strSearch replace all concurrent matches

'*            of strMatch with strReplace.  The matches must all be on the

'*            left side of the string starting at position 1. If after

'*            replacing the current occurance another occurance appears it

'*            will be replaced as well until no more concurrent occurances

'*            appear.

'*

'* Input:  strSearch   A string to be searched.

'*          strMatch   A starting string/Character to search for in strSearch.

'*        strReplace   A string to replace strMatch with.

'*           blnCase   Optional. A boolean indicating case sensitive searches

'*                       True  = Case Sensitive Search

'*                       False = Case Insensitive Search (Default)

'*

'* Output: Returns strSearch with the left side occurances of the strMatch

'*           replaced with strReplace.

'*

'* Example:

'*   LReplace(" This is a test", " ", "&nbsp", False) = &nbspThis is a test

'*

'* Calls:

'* ReturnCaseComparisonValue

'*

'* Changes:

'* 2008-12-03: Use ReturnCaseComparisonValue to return intSearch instead

'*               of custom IF statement

'********************************************************************

Function LReplace(ByVal strSearch, ByVal strMatch, ByVal strReplace, ByVal blnCase)

  'Version: 1.1 2008-12-06

  Dim strLeft, intSearch

 

  intSearch = ReturnCaseComparisonValue(blnCase)

 

  Do While InStr(1, strSearch, strMatch, intSearch) = 1

    'Remove the strMatch from strSearch

    strSearch = Replace(strSearch, strMatch, "", 1, 1, intSearch)

    'Add strReplace to strLeft

    strLeft = strLeft & strReplace

  Loop 'While InStr(1, strSearch, strMatch, intSearch) = 1

 

  LReplace = strLeft & strSearch

End Function 'LReplace

 

Article ID: 406, Created On: 9/25/2011, Modified: 9/25/2011