相关疑难解决方法(0)

用单反斜杠替换双反斜杠

我有一个字符串“ \\ u003c”,它属于UTF-8字符集。由于存在双反斜杠,因此我无法将其解码为unicode。如何从“ \\ u003c”获取“ \ u003c”?我正在使用Java。

我尝试过

myString.replace("\\\\", "\\");
Run Code Online (Sandbox Code Playgroud)

但无法实现我想要的。

这是我的代码

String myString = FileUtils.readFileToString(file);
String a = myString.replace("\\\\", "\\");
byte[] utf8 = a.getBytes();

// Convert from UTF-8 to Unicode
a = new String(utf8, "UTF-8");
System.out.println("Converted string is:"+a);
Run Code Online (Sandbox Code Playgroud)

文件的内容是

\ u003c

java string replace character-encoding backslash

5
推荐指数
2
解决办法
2万
查看次数

标签 统计

backslash ×1

character-encoding ×1

java ×1

replace ×1

string ×1