替换字符串中的字母 [英] Replace letters in a string

查看:305
本文介绍了替换字符串中的字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有一个问题,我不知道如何解决。问题是我甚至不知道如何谷歌。我已经花了几个小时在互联网上寻找解决方案,但没有成功。情况是这样的:

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:

用c替换č

用e替换ė

用e

等等..

也许有人可以帮助我?我有一个答案,但它不是很优化,我希望有一些更方便的解决方案。

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

提前致谢!

推荐答案

让框架为你做转换:

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);

此日志:

new: aabccdeeefghiijzz

这篇关于替换字符串中的字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆