簡體   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