using Replace Efficiently....

Results 1 to 2 of 2

Thread: using Replace Efficiently....

  1. #1
    Join Date
    Dec 1969

    Default using Replace Efficiently....

    I have a sub I use to loop thru large blocks of text and replace I have many many replace statements such as:<BR>strInput = Replace("" & strInput,vbcrlf," ")<BR>strInput = Replace("" & strInput,vbCr," ")<BR>strInput = Replace("" & strInput,vbLf," ")<BR>strInput = Replace("" & strInput,":-)","&#060;img src=""/SmartText/i.gif""&#062;") <BR><BR>Is there a more efficient way to do this? and am I going to use alot of memory doing it this way?<BR><BR>Thanks!

  2. #2
    Join Date
    Dec 1969

    Default RE: using Replace Efficiently....

    Why do you concatenate "" to every string?<BR><BR>Yes, doing it the very first time is a good idea, to ensure that you *have* a string. But on all subsequent Replace calls, you *know* that you have a string because Replace itself is guaranteed to return a string.<BR><BR>That extra concatenate, alone, is *doubling* your memory usage.<BR><BR>Why do you Replace vbcrlf *and* vbcr *and* vblf??? If you replace vbcr and vblf individually, what&#039;s the point of replacing the combo?<BR><BR>If you have many substrings that you replace with the same thing (e.g., vbcr and vblf both get replaced with space), then using a regular expression would improve things a lot, but if the replacement is different each time (as in your last example) then stick with what you have.<BR><BR>Is there a *lot* more efficient way? Probably not.

Posting Permissions

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