I\'m trying to manipulate a string.
After extracting all the vowels from a string, I want to replace all the \'v\' with \'b\' and all the \'b\' with \'v\' from the
You have done it half-way actually, the only thing to take note is that when you want to "swap" the string, you got to create "temporary" string instead of replacing is directly.
What you did was this:
ccvb
ccbb #cannot distinguish between what was changed to b and the original b
ccvv #thus both are changed together
Consider using the non existent character in the string as the first replacement. Let say, I now change all b with 1 first:
s2 = s2.replace("b","1")
s2 = s2.replace("v","b")
s2 = s2.replace("1","v")
Then you will get:
ccvb #original
ccv1 #replace b with 1
ccb1 #replace v with b
ccbv #replace 1 with v
The most important point here is the use of the temporary string