如何替换java字符串中的unicode字符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23024609/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 20:06:59  来源:igfitidea点击:

How can I replace a unicode character in java string

java

提问by user3173814

I have an issue in my project that is replacing a unicode charcter with another unicode character in a Java string. After searching and trying different codes , I did'nt get the solution for that I want to replace a character in Persian to another character in Persian with different unicode number. I really appreciate any help.

我的项目中有一个问题,就是用 Java 字符串中的另一个 unicode 字符替换 unicode 字符。在搜索并尝试不同的代码后,我没有得到解决方案,因为我想将波斯语中的一个字符替换为具有不同 unicode 编号的波斯语中的另一个字符。我真的很感激任何帮助。

thanks

谢谢

采纳答案by Raju Sharma

Trying this will solve your issue.

试试这个会解决你的问题。

str.replaceAll("\p{Sc}", string_to_replcae);

and example can be like below:

示例如下:

String str = "For some reason my ?double quotes? were lost.";
    str = str.replaceAll("\uFFFD", "\"");

this example can be viewed from here : How to replace � in a string

这个例子可以从这里查看:How to replace � in a string

follow the link for more unicode expressions. http://www.regular-expressions.info/unicode.html

点击链接了解更多 unicode 表达式。http://www.regular-expressions.info/unicode.html