replace entire case only

spinkung

Registered User.
Local time
Today, 17:31
Joined
Dec 4, 2006
Messages
267
hi

i'm using

Code:
mystring = replace(mystring, aValue, "")

to replace duplicates in a string used to build an sql string.

i.e. i could have...

1,2,201,55,202,3,40,55, 555, 22, 222, 22

so if i use the replace on the 22 it SHOULD only replace the other 22. whats happening is its replacing the 222 as well. the same will happen for the 555.

can i use this to replace only if its a full match, i.e. the whole string?

Thanks
 
Perhaps pad the search string with the delim character on either side of it, and make sure that the string also has the delim character on either side of it to be able to find/replace the search string as the first/last item in that search string.

Otherwise, looks like a reliable solution to me.
 
Also, notice that the Replace() function ...
1) ...allows you to specify the start location of the replace
- - so it only performs a replace AFTER that position in the string
2) ...allows you to specify how many replaces to do
- - so set the Count parameter to 1 and the function only replace one instance of your search string.
 
so what should the string look like if your function did what you wanted it to do?

"1,2,201,55,202,3,40,55, 555, , 222, " ?
 

Users who are viewing this thread

Back
Top Bottom