Python 有非常有用的 string.startswith()
和 string.endswith()
函数。
我可以使用哪些 NSString 方法来实现相同的功能?
最佳答案
使用 -hasPrefix:
和 -hasSuffix:
:
NSString *s = @"foobar";
NSLog(@"%d %d\n", [s hasPrefix:@"foo"], [s hasSuffix:@"bar"]);
// Output: "1 1"
关于python - Objective-C (cocoa) 等价于python的endswith/beginswith,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5201965/