Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective-C(cocoa)相当于python';s endswith/beginswith_Python_Objective C_Cocoa - Fatal编程技术网

Objective-C(cocoa)相当于python';s endswith/beginswith

Objective-C(cocoa)相当于python';s endswith/beginswith,python,objective-c,cocoa,Python,Objective C,Cocoa,Python具有非常有用的string.startswith()和string.endswith()函数。 我可以使用哪些NSString方法来实现相同的功能?您需要和消息 我也倾向于定期使用消息来实现相同的效果,但不区分大小写比较。使用和: -hasPrefix()和-hasSuffix()返回是或否,具体取决于接收器是以给定的子字符串开始还是结束。如果startswith()和endswith()就是这样做的,那么这就是你的答案 NSString *s = @"foobar"; NSLog(

Python具有非常有用的
string.startswith()
string.endswith()
函数。 我可以使用哪些NSString方法来实现相同的功能?

您需要和消息

我也倾向于定期使用消息来实现相同的效果,但不区分大小写比较。

使用和:

-hasPrefix()和-hasSuffix()返回是或否,具体取决于接收器是以给定的子字符串开始还是结束。如果startswith()和endswith()就是这样做的,那么这就是你的答案

NSString *s = @"foobar";
NSLog(@"%d %d\n", [s hasPrefix:@"foo"], [s hasSuffix:@"bar"]);
// Output: "1 1"