zl程序教程

您现在的位置是:首页 >  其它

当前栏目

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

字符串 是否 swift 后缀 相等
2023-09-27 14:27:38 时间

相等和不等  == !=

前缀相等 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")


效果截图