Objective-C(可可)相当于python的endwith / startswith [英] Objective-C (cocoa) equivalent to python's endswith/beginswith

查看:570
本文介绍了Objective-C(可可)相当于python的endwith / startswith的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python有 string.startswith() string.endswith()函数非常有用。
我可以使用什么NSString方法来拥有相同的函数?

Python has string.startswith() and string.endswith() functions which are pretty useful. What NSString methods can I use to have the same function?

推荐答案

使用 -hasPrefix: -hasSuffix:

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

这篇关于Objective-C(可可)相当于python的endwith / startswith的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆