/*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;
}
将字符串按照单词逆序
最新推荐文章于 2023-02-22 00:04:02 发布