ios - 如何替换 UITextView 中的特定字符

标签 ios swift xcode

嗨,在日志窗口中,我有两个数组。第一个是我的彩色数组,因为您可以看到模拟器中的蓝色数组。我想用第二个数组更改/替换蓝色数组,但它们是我的和弦。

Screenshot

实际上,我尝试了以下代码,但所有蓝色文本都更改为“Dbm”,这是第二个数组的第一个字符串。

for txt in coloredTexts {

    for transposed in transposedAkorArray{
        
        self.akor_goster.text = self.akor_goster.text.replacingOccurrences(of: "\(txt)", with: "\(transposed)")
    }
    
}

最佳答案

尝试,

for (index,txt) in coloredTexts.enumerated() {
    let range = akor_goster.text.range(of: txt)
    akor_goster.text.replacingOccurrences(of: txt, with: transposedAkorArray[index], options: [], range: range)
}

关于ios - 如何替换 UITextView 中的特定字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63828951/

相关文章:

ios - 如何让 iOS 13 map 同时显示用户位置和另一个注释,即使它们靠得很近

iOS - 是否可以将 statusBarStyle 更改为自定义颜色?

ios - NSArray 在方法结束时丢失值

ios - 在 Firebase 上存储图像不起作用

iOS 自定义字体 "Floats"太高

ios - swift : SLKTextViewController's left button is not viewed

ios - 如何管理 Podfile - iPhone、iPad 和 Mac 10.15 的部署

ios - 创建随机数的类实例 - Swift

xcode - Swift:如何将协议(protocol)类型转换为特定协议(protocol)?

ios - 无法监视事件循环并等待应用程序空闲