aaa.heic.jjj.heic to aaa.heic.jjj.jpg
let str = "aaa.heic.jjj.heic"
if let range = str.lowercased().range(of:".heic", options: [.backwards], range: nil, locale: nil) {
str.replacingCharacters(in: range, with: ".jpg")
}
Ref.
How do I find the last occurrence of a substring in a Swift string?
Fred S. changed 3 years agoView mode Like Bookmark
swift 版本
// 將 uploadCount 設為紅色
let text = "已為您上傳 \(uploadCount) 個項目。"
let mutableAttributedString = NSMutableAttributedString(string: text)
do {
let regex = try NSRegularExpression(pattern: "\(uploadCount)", options: [])
let range = NSRange(location:0, length: text.count)
regex.enumerateMatches(in: text, options: [], range: range) {
(result: NSTextCheckingResult?, _, _) in
Fred S. changed 3 years agoView mode Like Bookmark