`
lovebirdegg
  • 浏览: 171757 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

how to reverse a nsstring

阅读更多

原文:http://lovebirdegg.co.tv/2010/04/how-to-reverse-a-nsstring/
some time you want to recerse a nsstring

for example:

"你好"to"好你"


i Searched the api but have no result,the method above can solute it
NSString *content = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];



int len = [content length];

// Auto released string



NSString * reversedStr = [[NSMutableString alloc] init];



// Probably woefully inefficient...

while (len > 0)

[reversedStr appendString:

[NSString stringWithFormat:@"%C", [content characterAtIndex:--len]]];

NSLog(reversedStr);

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics