let range: Range =“包含所有字符”.range(of: "子字符串")!
location 子字符串位置
let location = fixStr.distance(from: fixStr.startIndex, to:range.lowerBound)
应用
let fixStr = "照片需免冠,建议未化妆,五官清晰可鉴,完整露出手臂;证件需展示人像面;手写声明为“姓名+申请日期+www.linkkt.one+我在本站的所有行为均为本人操作,并已知悉相关风险,愿意承担相关操作的一切法律后果”。"
let attrString = NSMutableAttributedString(string: fixStr)
let range: Range = fixStr.range(of: "姓名+申请日期+www.linkkt.one+我在本站的所有行为均为本人操作,并已知悉相关风险,愿意承担相关操作的一切法律后果")!
let location = fixStr.distance(from: fixStr.startIndex, to:range.lowerBound)
let attr: [NSAttributedString.Key : Any] = [.font: UIFont.init(name: "Helvetica-Bold", size: 14),]
attrString.addAttributes(attr, range: NSRange(location: location, length: "姓名+申请日期+www.linkkt.one+我在本站的所有行为均为本人操作,并已知悉相关风险,愿意承担相关操作的一切法律后果".count ))
最后
以上就是激昂彩虹最近收集整理的关于swift 字符串中查找字符位置的全部内容,更多相关swift内容请搜索靠谱客的其他文章。
发表评论 取消回复