Replace command

leptictidium
09-13-2009, 03:27 PM
I have a string called algorithm. I want to replace all the letters "B" in this string with "U", all the "F"s with "D"s, all the "U"s with "F"s, and all the "D"s with "B"s. This code doesn't work because if the original string is "B", then the final string will be "F" instead of "U".

algorithm = Replace(algorithm, "B", "U")
algorithm = Replace(algorithm, "F", "D")
algorithm = Replace(algorithm, "U", "F")
algorithm = Replace(algorithm, "D", "B")

How do i fix this? Thx for any help!

kassyopeia
09-13-2009, 03:52 PM
The easiest way is to find a special character that you're certain isn't present in the string, and use that as a placeholder and work backwards:

algorithm = Replace(algorithm, "B", "#")
algorithm = Replace(algorithm, "D", "B")
algorithm = Replace(algorithm, "F", "D")
algorithm = Replace(algorithm, "U", "F")
algorithm = Replace(algorithm, "#", "U")

leptictidium
09-13-2009, 03:58 PM
Wow! Thanks! I never would have imagined that it would be that easy! I always make things more complicated than they have to be...lol. :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum