objective c - Replace occurrences of two characters with each other in a string -


i have problem need invert 2 characters within string. example, if string "a*b/c" , want replace occurrences of * / , / *. want resulting string "a/b*c".

using method stringbyreplacingoccurrenceofstring: doesn't work because don't want first round of replacements affect second:

string = @"a*b/c"; [string stringbyreplacingoccurrencesofstring:@"*" withstring:@"/"]; [string stringbyreplacingoccurrencesofstring:@"/" withstring:@"*"]; 

this results in "a*b*c", not want. know efficient way of accomplishing this?

string = @"a*b/c"; [string stringbyreplacingoccurrencesofstring:@"*" withstring:@"&"]; [string stringbyreplacingoccurrencesofstring:@"/" withstring:@"*"]; [string stringbyreplacingoccurrencesofstring:@"&" withstring:@"/"]; 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -