The first method: (note the processing of Chinese strings)
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSString *[email protected] "I am a string";
Nsmutablestring *str1=[nsmutablestring string];
Nsmutablestring *str2=[nsmutablestring stringwithutf8string:[str utf8string];
int i=0;
while (I!=[STR2 length])
{
NSString *str3=[str2 substringwithrange:nsmakerange ([str2 length]-i-1, 1)];
[Str1 appendformat:@ "%@", STR3];
i++;
}
NSLog (@ "str1:%@", str1);
return 0;
}
The second method: (note the processing of Chinese strings)
int main (int argc, const char * argv[])
{
NSString *str = @ "I am a string";
Nsmutablestring *str1=[nsmutablestring string];
int i=0;
Nsmutablestring *str2=[nsmutablestring stringwithutf8string:[str utf8string];
NSLog (@ "str2:%@", str2);
while (I!=[STR2 length])
{
Unichar ch=[str2 characteratindex:[str2 length]-i-1];
NSString *str4=[nsstring stringwithcharacters:&ch length:1];
[Str1 APPENDSTRING:STR4];
i++;
}
NSLog (@ "str1:%@", str1);
return 0;
}
Objectiv-c two methods to implement string inverse order