Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace letters in a string

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!

like image 961
Lukas Avatar asked Dec 04 '22 16:12

Lukas


1 Answers

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
like image 71
Dave DeLong Avatar answered Dec 28 '22 01:12

Dave DeLong