python - Objective-C (cocoa) 等价于python的endswith/beginswith

标签 python objective-c cocoa

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/

相关文章:

ios - 从 UILabel 或 UITextField 更改 UIButton 的标题

objective-c - - [NSTextField 数据使用编码 :allowLossyConversion:] unrecognised selector sent to instance

iphone开发-豹子还是雪豹?

objective-c - 为什么使用setLevel : won't make the window higher than a full screen game?

python - 使用两个列表创建不同的句子

python - 如何在keras中单独使用Autoencoder的编码器?

objective-c - 将 Facebook 集成到 Xcode 4.3

Python:使用 Chrome 浏览器进行操作

python - 作为自创建对象构造函数的类方法

ios - 获取uitableview的多个选定行信息