ITeye博客

how to reverse a nsstring

lovebirdegg · 2010-04-16 10:04 · objective-c · 移动开发 · C · C++ · C# · Markdown

原文: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)

暂无评论。

评论功能维护中,当前仅展示历史评论。