相等和不等  == !=

前缀相等 hasPrefix(_:)

后缀相等 hasSuffix(_:)

code:

//: A UIKit based Playground for presenting user interface

import UIKit

//截取逗号前面数值
let welcome = "hello,world"
let index = welcome.index(of: ",") ?? welcome.endIndex
let subString = welcome[..<index]

let newStringHello = String(subString)

let welcome1="hello"
// 比较运算
print(welcome==welcome1)
welcome.hasPrefix("hello")
welcome.hasSuffix("world")
welcome1.hasSuffix("world")

效果截图

swift 字符串是否相等 前后缀 是否相等_sed