- #import <Foundation/Foundation.h>
- int main(int argc, const char * argv[]) {
- @autoreleasepool {
-
-
- NSString *str1=@"abc";
- NSString *str2=@"Abc";
- NSString *str3=[NSString stringWithFormat:@"abc"];
- //isEqualToString 区分大小写 返回值bool类型
- if ([str1 isEqualToString:str2]) {
-
- NSLog(@"yes");
- }else{
-
- NSLog(@"no");
-
- }
-
-
- //compare 默认区分大小写 NSCaseInsensitiveSearch不区别大小写
- NSComparisonResult result=[str1 compare:str2 options:NSCaseInsensitiveSearch];
-
- switch (result) {
- case NSOrderedAscending:
- NSLog(@"a<b,升序");
- break;
- case NSOrderedDescending:
- NSLog(@"a>b,降序");
- break;
- case NSOrderedSame:
- NSLog(@"a==b,相等");
- break;
- default:
- break;
- }
-
- //hasPrefix 前缀检测 返回值为bool类型 [url hasPrefix:@"http://"]用方括号括起来
- NSString *url=@"http://www.baidu.com";
- if ([url hasPrefix:@"http://"]) {
- NSLog(@"这是一个网址");
- }else{
-
- NSLog(@"这不是一个网址");
- }
-
- //hasSuffix 后缀
- if ([url hasSuffix:@"du.com"]) {
- NSLog(@"这是一个网址");
- }else{
-
- NSLog(@"这不是一个网址");
- }
-
-
-
- NSString *str4=@"asdasdasdasdascatincsadadlajs;";
- NSString *str5=@"catin=";
- //查找子字符串返回首次出现位置 和长度
- NSRange range= [str4 rangeOfString:str5];
- // 查找不到range.location会返回 NSNotFound range.length返回为0
- if (range.location!=NSNotFound || range.length!=0) {
-
- NSLog(@"%lu\n%lu",range.location,range.length);
-
- }else{
-
- NSLog(@"没有找到....");
- }
-
-
-
-
- }
- return 0;
- }
复制代码
|
|