无法替换°字符

Hoo*_*oli 2 java netbeans

我有

String test = "an°ther";
Run Code Online (Sandbox Code Playgroud)

我想,以取代°o,但是当我使用

test.replaceAll("°", "o");
Run Code Online (Sandbox Code Playgroud)

我真正运行的是test.replaceAll("º", "o")因为当我复制并粘贴它时,这是什么字符进入IDE.

有没有办法获得ASCII值或基于其他一些标准替换?

Mar*_*oun 5

您可以使用°符号(度数符号)的unicode编号:U+00B0.另请注意,您不需要replaceAll(您在这里不使用正则表达式,replace就足够了):

String test = "an°ther";
System.out.println(test.replace("\u00B0", "o"));
// another
Run Code Online (Sandbox Code Playgroud)