[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