【发布时间】:2018-06-06 12:03:16
【问题描述】:
假设我有一个字符串:“\\u2026”。而且,我希望它将其更改为 "\u2026" 以在 Scala 中打印出 unicode。有没有办法做到这一点?感谢您的宝贵时间。
编辑: 让我澄清一下。由于某些情况,我有一个字符串,例如:“Following char is in unicode: \\u2026”,打印:
以下字符为 unicode:\u2026
但是,我想编辑它以便打印:
下面的 char 是 unicode:…
感谢您的回答。这就是我最终要做的。
def FixString(string: String) : String = {
var newString = string;
// Find the 1st problematic string
var start = string.indexOf("\\u");
while(start != -1) {
// Extract the problematic string
val end = start + 6;
val wrongString = string.substring(start,end);
// Convert to unicode
val hexCode = wrongString.substring(2);
val intCode = Integer.parseInt(hexCode, 16);
val finalString = new String(Character.toChars(intCode));
// Replace
newString = string.replace(wrongString,finalString);
// Find next problematic string
start = string.indexOf("\\u", end);
}
return newString;
}
【问题讨论】:
-
您只想删除双反斜杠吗?