/*2.将字符串按照单词逆序 输入一段字符串,已知字符串只由字母和空格构成,将字符串按照单词逆序 传入@"welcome to beijing" 返回 @"beijing to welcome" */ + (NSString *)reverseWordsInString:(NSString *)str //{ // NSArray * arr= [str componentsSeparatedByString:@" "]; // NSArray * arr1=[[arr reverseObjectEnumerator]allObjects]; // NSString * str1 = [arr1 componentsJoinedByString:@" "]; // return str1;//[arr copy]; //} //{ // NSArray * array = [str componentsSeparatedByString:@" "]; // NSArray * array1 = [[array reverseObjectEnumerator]allObjects]; // NSString * str1 = [array1 componentsJoinedByString:@" "]; // return str1; //} { NSArray * array = [str componentsSeparatedByString:@" "]; NSArray * array1 = [[array reverseObjectEnumerator]allObjects]; NSString * str1 = [array1 componentsJoinedByString:@" "]; return str1; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-12-20 10:30:39