繁体   English   中英

如何替换 UITextView 中的特定字符

[英]How can I replace specific characters in UITextView

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

截屏

实际上我在下面的代码中尝试过,但所有蓝色文本都用“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)
}

我认为你正在尝试做这样的事情:

for i in 0..<coloredTexts.count {
    self.akor_goster.text = self.akor_goster.text.replacingOccurrences(of: "\(coloredTexts[i])", with: "\(transposedAkorArray[i])")
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM