[email protected]
[email protected]
输出:
chris
steve
我期待得到@
字符前的子字符串。在Python中,我会使用类似于:myString = myString[:myString.find("@")]
,但我认为Swift的版本非常复杂,至少从我读过的内容来看。在这种情况下桥接Obj-C会更好吗,因为Swift的indexOf/find函数看起来像这样的混乱:Finding index of character in Swift String?
这样的事情,即使它使用数组,似乎是simpliest路线:
contact = contact.componentsSeparatedByString("@")[0]
没有错,你提出的解决方案。 – CuriousRabbit