Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Hello i have a problem that i don't know how to solve. The problem is that I even don't know how to google about it. I've already spent hours on the internet finding the solution, but didn't succeeded. The situation is like this:

I have String, lets say:

NSString *string = @"a?bc?de??fghi?jz?";

my result has to be like this:

NSString *string = @"aabccdeeefghiujzz";

So if you understood i have to do this:

replace ? with a

replace ? with c

replace ? with e

replace ? with e

and so on..

Maybe anyone could help me? i have an answer but it's not very optimized, i am hoping for some more convenient solution.

Thanks in advance!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
827 views
Welcome To Ask or Share your Answers For Others

1 Answer

Let the frameworks do the conversion for you:

NSString *blah = @"a?bc?de??fghi?jz?";
NSData *data = [blah dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *newblah = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSLog(@"new: %@", newblah);

This logs:

new: aabccdeeefghiijzz

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...