|
-
Jul 21st, 2009, 05:30 PM
#1
Thread Starter
Frenzied Member
[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?
-
Jul 21st, 2009, 06:41 PM
#2
Thread Starter
Frenzied Member
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, ",,", ",")
-
Jul 21st, 2009, 07:03 PM
#3
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
-
Jul 22nd, 2009, 08:56 AM
#4
Addicted Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|