- int main(int argc, const char * argv[]) {
- @autoreleasepool {
- NSString *ul=@"http://ios.itcast.cn";
- //http:// https://
- if([ul hasPrefix:@"http://"]||[ul hasPrefix:@"https://"]){
- NSLog(@"yes");
- }else{
- NSLog(@"no");
- }
- NSString * str1=@"ahdgdioskvhsyios";
- NSString *s2=@"ios";
- NSRange r=[str1 rangeOfString:s2];
-
- if (r.location!=NSNotFound) {
- NSLog(@"%lu,%lu",r.location,r.length);
- } else {
- NSLog(@"");
- }
- }
- return 0;
- }
复制代码- (BOOL)hasPrefix:(NSString *)aString;//前缀检查 - (BOOL)hasSuffix:(NSString *)aString;//后缀检查 - (NSRange)rangeOfString:(NSString *)aString;//查找字符串,返回字符串所在的位置和长度
|