2024-09-20 04:15:35 发布
网友
Python有非常有用的string.startswith()和string.endswith()函数。 我可以使用哪些NSString方法来拥有相同的函数?
string.startswith()
string.endswith()
使用^{}和^{}:
NSString *s = @"foobar"; NSLog(@"%d %d\n", [s hasPrefix:@"foo"], [s hasSuffix:@"bar"]); // Output: "1 1"
您需要^{}和^{}消息。
我倾向于经常使用^{}消息来实现相同的但不区分大小写的比较。
-hasPrefix()和-hasuffix()返回YES或NO,这取决于接收器是以给定的子字符串开始还是结束。如果startswith()和endswith()就是这样做的,那么这就是您的答案。
使用^{} 和^{} :
您需要^{} 和^{} 消息。
我倾向于经常使用^{} 消息来实现相同的但不区分大小写的比较。
-hasPrefix()和-hasuffix()返回YES或NO,这取决于接收器是以给定的子字符串开始还是结束。如果startswith()和endswith()就是这样做的,那么这就是您的答案。
相关问题 更多 >
编程相关推荐