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

Cra*_*Dev 5 xcode objective-c nsstring

我必须验证字符串的开头:我的示例字符串是

NSString *string1 = @"Hello World";
Run Code Online (Sandbox Code Playgroud)

然后我必须做一个if,例如:

 if (string1 startwith "Hello")
Run Code Online (Sandbox Code Playgroud)

我怎么能在目标c中做到这一点?

Jim*_*ler 36

if ([string1 hasPrefix:@"Hello"])
Run Code Online (Sandbox Code Playgroud)