零基础 Object-C 学习路线推荐 : Object-C 学习目录 >> Object-C 基础
零基础 Object-C 学习路线推荐 : Object-C 学习目录 >> Object-C 线程
零基础 Object-C 学习路线推荐 : Object-C 学习目录 >> OpenGL ES
零基础 Object-C 学习路线推荐 : Object-C 学习目录 >> GPUImage
零基础 Object-C 学习路线推荐 : Object-C 学习目录 >> AVFoundation
零基础 Object-C 学习路线推荐 : Object-C 学习目录 >> CocoaPods
一.NSString 字符串的排序
1.sortedArrayUsingComparator
/******************************************************************************************/
//@Author:猿说编程
//@Blog(个人博客地址): www.codersrc.com
//@File:Object-C NSString 字符串的排序
//@Time:2021/09/02 08:00
//@Motto:不积跬步无以至千里,不积小流无以成江海,程序人生的精彩需要坚持不懈地积累!
/******************************************************************************************/
-(BOOL)stringSort
{
NSArray *srcArray = @[@"ReplaceableVideoOrPic3",
@"ReplaceableText100",
@"ReplaceableVideoOrPic1",
@"ReplaceableVideoOrPic2",
@"ReplaceableText0",
@"ReplaceableVideoOrPic24",
@"ReplaceablePic24",
@"ReplaceablePic0",
@"ReplaceablePic5",
@"ReplaceableText5",
@"ReplaceableVideoOrPic14"];
NSLog(@"srcArray:%@",srcArray);
NSArray *dstArray = [srcArray sortedArrayUsingComparator:^(NSString * obj1, NSString * obj2){
return (NSComparisonResult)[obj1 compare:obj2 options:NSNumericSearch];
}];
NSLog(@"dstArray:%@",dstArray);
return YES;;
}
/*
srcArray:(
ReplaceableVideoOrPic3,
ReplaceableText100,
ReplaceableVideoOrPic1,
ReplaceableVideoOrPic2,
ReplaceableText0,
ReplaceableVideoOrPic24,
ReplaceablePic24,
ReplaceablePic0,
ReplaceablePic5,
ReplaceableText5,
ReplaceableVideoOrPic14
)
dstArray:(
ReplaceablePic0,
ReplaceablePic5,
ReplaceablePic24,
ReplaceableText0,
ReplaceableText5,
ReplaceableText100,
ReplaceableVideoOrPic1,
ReplaceableVideoOrPic2,
ReplaceableVideoOrPic3,
ReplaceableVideoOrPic14,
ReplaceableVideoOrPic24
)
*/
2.sortedArrayUsingSelector
/******************************************************************************************/
//@Author:猿说编程
//@Blog(个人博客地址): www.codersrc.com
//@File:Object-C NSString 字符串的排序
//@Time:2021/08/31 08:00
//@Motto:不积跬步无以至千里,不积小流无以成江海,程序人生的精彩需要坚持不懈地积累!
/******************************************************************************************/
-(BOOL)stringSort
{
NSArray *srcArray = @[@"ReplaceableVideoOrPic3",
@"ReplaceableText100",
@"ReplaceableVideoOrPic1",
@"ReplaceableVideoOrPic2",
@"ReplaceableText0",
@"ReplaceableVideoOrPic24",
@"ReplaceablePic24",
@"ReplaceablePic0",
@"ReplaceablePic5",
@"ReplaceableText5",
@"ReplaceableVideoOrPic14"];
NSLog(@"srcArray:%@",srcArray);
NSArray *dstArray = [srcArray sortedArrayUsingSelector:@selector(compare:)];//这个是一直默认升序
NSLog(@"dstArray:%@",dstArray);
return YES;;
}
/*
srcArray:(
ReplaceableVideoOrPic3,
ReplaceableText100,
ReplaceableVideoOrPic1,
ReplaceableVideoOrPic2,
ReplaceableText0,
ReplaceableVideoOrPic24,
ReplaceablePic24,
ReplaceablePic0,
ReplaceablePic5,
ReplaceableText5,
ReplaceableVideoOrPic14
)
dstArray:(
ReplaceablePic0,
ReplaceablePic24,
ReplaceablePic5,
ReplaceableText0,
ReplaceableText100,
ReplaceableText5,
ReplaceableVideoOrPic1,
ReplaceableVideoOrPic14,
ReplaceableVideoOrPic2,
ReplaceableVideoOrPic24,
ReplaceableVideoOrPic3
)
*/
3.sortedArrayUsingDescriptors
/******************************************************************************************/
//@Author:猿说编程
//@Blog(个人博客地址): www.codersrc.com
//@File:Object-C NSString 字符串的排序
//@Time:2021/08/31 08:00
//@Motto:不积跬步无以至千里,不积小流无以成江海,程序人生的精彩需要坚持不懈地积累!
/******************************************************************************************/
-(BOOL)stringSort
{
NSArray *srcArray = @[@"ReplaceableVideoOrPic3",
@"ReplaceableText100",
@"ReplaceableVideoOrPic1",
@"ReplaceableVideoOrPic2",
@"ReplaceableText0",
@"ReplaceableVideoOrPic24",
@"ReplaceablePic24",
@"ReplaceablePic0",
@"ReplaceablePic5",
@"ReplaceableText5",
@"ReplaceableVideoOrPic14"];
NSLog(@"srcArray:%@",srcArray);
//yes升序排列,no,降序排列
NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:nil ascending:NO];
//注意这里的ary进行排序后会生产一个新的数组指针
NSArray *dstArray = [srcArray sortedArrayUsingDescriptors:[NSArray arrayWithObjects:descriptor, nil]];
NSLog(@"dstArray:%@",dstArray);
return YES;;
}
/*
srcArray:(
ReplaceableVideoOrPic3,
ReplaceableText100,
ReplaceableVideoOrPic1,
ReplaceableVideoOrPic2,
ReplaceableText0,
ReplaceableVideoOrPic24,
ReplaceablePic24,
ReplaceablePic0,
ReplaceablePic5,
ReplaceableText5,
ReplaceableVideoOrPic14
)
dstArray:(
ReplaceablePic0,
ReplaceablePic24,
ReplaceablePic5,
ReplaceableText0,
ReplaceableText100,
ReplaceableText5,
ReplaceableVideoOrPic1,
ReplaceableVideoOrPic14,
ReplaceableVideoOrPic2,
ReplaceableVideoOrPic24,
ReplaceableVideoOrPic3
)
*/
二.猜你喜欢
- Xcode – The application’s Info.plist does not contain CFBundleShortVersionString.
- Xcode – This app has attempted to access privacy-sensitive data without a usage description.
- Xcode replace 使用正则表达式替换文字
- Object-C 获取系统字体和字体名字
- Object-C 加载 TTF/OTF/TTC 文件
- Object-C private var mobileDevice文件夹
- Object-C 保存文件到相册
- NSString 字符串的排序
ChatGPT 3.5 国内中文镜像站免费使用啦
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容