[RESOLVED] Replace All Duplicates in String
I have a method that builds up a comma separated list returned as a string.
Unfortunately it sometimes returns stuff like
Code:
Tom,,,,,,Dick,,,,,,Harry
I tried replace to return single commas e.g
Code:
Replace (strNames, ",,", ",")
but it only replaces some of them. e.g.
Is there a recursive ReplaceAll function or do I have to write my own?
Re: Replace All Duplicates in String
So far I am doing it multiple times to try and catch all commas (very error prone).
vb Code:
strNames = Replace (strNames, ",,", ",")
strNames = Replace (strNames, ",,", ",")
strNames = Replace (strNames, ",,", ",")
strNames = Replace (strNames, ",,", ",")
Re: Replace All Duplicates in String
yeah, that's pretty much how it works.... I would put it in a while loop though... so that While there are ",," in your string, do the replace... as soon as there are no more ",," in there, it'll stop the loop...
-tg
Re: [RESOLVED] Replace All Duplicates in String
vb Code:
Dim strNames As String
strNames = "Tom,,,,,,Dick,,,,,,Harry"
Do While InStr(1, strNames, ",,") > 0
strNames = Replace(strNames, ",,", ",")
Loop
Debug.Print strNames