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

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -