NSString的比较专栏
先做个笔记不做具体说明,有空了再补上
NSString *str; // 使用stringWithFormat生成一格式化字符串 str = [NSString stringWithFormat:@"This is %@","John"]; NSLog(@"str--->%@",str); // 字符串长度length; NSLog(@"The length of this string is %@",[str length]); // 字符串比较 isEqualToString, 返回NO(false),isEqualToString区分大小写 BOOL isequal = [str isEqualToString:@"this is John"]; // 字符串序列比列 compare,返回结果NSComparisonResult // type enum _NSComparisonResult{ // NSOrderedAscending = -1, // NSOrderedSame, // NSOrderedDescending // } int result = [@"bool" compare:@"cool"]; NSLog(@"The result is %d",result); // compare 比较规则options // NSLiteralSearch 区分大小写(完全比较) // NSCaseInsensitiveSearch 不区分大小写 // NSNumericSearch 只比较字符串的个数,而不比较字符串的字面值 int result1 = [@"This is John" compare:@"this is John" options:NSCaseInsensitiveSearch | NSNumericSearch]; NSLog(@"The result is %d",result1); // 字符串开头是否包括另一字符串 hasPrefix,返回结果YES(true) BOOL isHas = [str hasPrefix:@"This"]; // 字符串结尾是否包括另一字符串 hasSuffix,返回结果YES(true) BOOL isHas = [str hasSuffix:@"John"]; // 查找字符串在另一字符串中的位置 NSRange range = [str rangeOfString:@"is" options:NSCaseInsensitiveSearch]; NSLog(@"The location in the string named 'str' of 'is' is @d",range.location);
感谢您的访问!
若对您有帮助或有兴趣请关注博客:http://www.cnblogs.com/Rong-Shengcom/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· Windows编程----内核对象竟然如此简单?