#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSString * str= @" alkufag gdaiodo ohdksdy 7jd l djj ";
//先去掉首位空格
str = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSMutableString * opStr = [NSMutableString string];
//反向按字符遍历字符串并添加到可变字符串opStr中
[str enumerateSubstringsInRange:NSMakeRange(0, str.length) options:NSStringEnumerationReverse|NSStringEnumerationByComposedCharacterSequences usingBlock:^(NSString * _Nullable substring, NSRange substringRange, NSRange enclosingRange, BOOL * _Nonnull stop) {
[opStr appendString:substring];
}];
NSLog(@"\n%@",opStr);
}
return 0;
}
-------------------------------------------------------
2015-10-01 20:50:51.500 2222[2430:138123]
jjd l dj7 ydskdho odoiadg gafukla
Program ended with exit code: 0
|