iOS搜索指定字符在字符串中的位置


 1 NSString *tmpStr = @"asd341234aaaaccd";  
 2 
 3   NSRange range;  
 4 
 5   range = [tmpStr rangeOfString:@"ccd"];  
 6 
 7 if (range.location != NSNotFound) {  
 8 
 9       NSLog(@"found at location = %lu, length = %lu",(unsigned long)range.location,(unsigned long)range.length);  
10 
11 NSString *ok = [tmpStr substringFromIndex:range.location];  
12 
13       NSLog(@"%@",ok);  
14 
15   }else{  
16 
17       NSLog(@"Not Found");  
18 
19   }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM