我需要比较一个字符串,在一个(if)语句中为字符串中的每个字符提供两种可能性,例如:
let str = "2 3 1 2"
if str == "(1||2) (2||3) (1||2) (1||2)" {
//Do Something
}我知道代码写得不正确,只是为了理解我的意思。
我曾在VB中使用(类似操作符),例如:
Dim s As String = "2 3 1 2"
If s Like "[1-2] [3-4] [2-3] [1-2]" Or s Like "[1-2] [1-2] [2-3] 2" Then
//Do something
End If我在斯威夫特身上找不到类似的东西。
请帮忙,谢谢。
发布于 2014-12-10 15:53:10
看起来您所要求的是对正则表达式的支持。它们并不直接存在于Swift (目前?)但是您可能想看看RegEx in Swift?和http://nomothetis.svbtle.com/clean-regular-expressions-using-conversions。
https://stackoverflow.com/questions/27404740
复制相似问题