iOS 字符串替换:如何用 Swift 代码替换字符串中的部分内容
在 iOS 中,可以使用 stringByReplacingOccurrencesOfString:withString: 方法来替换字符串中的某一部分。
示例代码如下:
let originalString = 'ios 字符串 替换/h5 替换成.'
let replacedString = originalString.replacingOccurrences(of: '/h5', with: '.')
print(replacedString) // 输出: ios 字符串 替换. 替换成.
在上面的示例中,我们使用 replacingOccurrences(of:with:) 方法将字符串中的 '/h5' 替换为 '.'。最后输出的结果为 'ios 字符串 替换. 替换成.'。
原文地址: https://www.cveoy.top/t/topic/qdcZ 著作权归作者所有。请勿转载和采集!