目标C:检查字符串的开头

| 我必须验证字符串的开头:我的示例字符串是
NSString *string1 = @\"Hello World\";
那么我必须做一个if例子:
 if (string1 startwith \"Hello\")
如何在目标c中做到这一点?     
已邀请:
if ([string1 hasPrefix:@\"Hello\"])
    
阅读NSString类的文档。您会发现各种各样的惊喜。     
用这种方式怎么样:
NSRange aRange = [myString rangeOfString:@\"Hello\"];
if (aRange.location ==NSNotFound) {
  NSLog(@\"string not found\");
} else {
  NSLog(@\"string was at index %d \",aRange.location);
}
根据范围,您可以确定项目在字符串中的何处     

要回复问题请先登录注册