如何将一个字符串(如"xPM - yPM")分割成两个字符串,Swift

How to split a string (such as "xPM - yPM") into two strings, Swift

如果我有一个字符串,例如 xAM - yPM,是否可以使用 - 作为拆分字符串的点将字符串拆分为 2 个字符串?

您可以使用componentsSeparatedByString函数:

var splittedArray = yourString.componentsSeparatedByString(" - ")
println(splittedArray[0]) // "xPM"
println(splittedArray[1]) // "yPM"