Replace without the Replace function (Answer)

Results 1 to 3 of 3

Thread: Replace without the Replace function (Answer)

  1. #1
    K Fowler Guest

    Default Replace without the Replace function (Answer)

    Yesterday, I was seeking some help on how to perform a Replace on a string without using the VBScript Replace Function. Unfortunately, no one answered my question. I must admit, I was in a hurry and looking for a quick answer (didn&#039t want to stay after hours). I was under the gun, this fix had to be made. So, I sucked it up, and found the answer (Not without some help from a coworker, of course). Nonetheless, the fix was made, the day was saved!<BR><BR>Now, I would like to share it with all of you. It&#039s argument list doesn&#039t allow for optional parameters, but, it gets the job done.<BR><BR>Function ReplaceChar(strValue, strFindThis, strReplaceWith)<BR> Dim intCurPos<BR> Dim intLastPos<BR> Dim strResult<BR><BR> On Error Resume Next<BR><BR> intLastPos = 1<BR> strResult = ""<BR><BR> intCurPos = InStr(intLastPos, strValue, strFindThis)<BR> Do Until (intCurPos = 0)<BR> strResult = strResult & Mid(strValue, intLastPos, intCurPos - intLastPos) & strReplaceWith<BR> intLastPos = intCurPos + Len(strFindThis)<BR> intCurPos = InStr(intLastPos, strValue, strFindThis)<BR> Loop<BR> strResult = strResult & Mid(strValue, intLastPos, Len(strValue) + 1 - intLastPos)<BR><BR> ReplaceChar = strResult<BR><BR>End Function

  2. #2
    Join Date
    Dec 1969

    Default RE: Replace without the Replace function (Answer)

    why was this needed?? just curious

  3. #3
    K Fowler Guest

    Default RE: Replace without the Replace function (Answer)

    Unfortunately, the powers that be, would not allow me to update the production server with an Updated version of VBScript. The version that resides on the server doesn&#039t support the Replace function. Of course, now that I have brought it to their attention, that we are seriously lacking features that we could benefit from, we will be updating it within a few days.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts