简体   繁体   English

在字符串中编码特殊字符

[英]Encoding Special Characters in String

I have a String with some special characters like this one. 我有一个带有一些特殊字符的字符串,像这样。

"45” £800 77” " - > might also have some other special chars

Note that above string its not double quotes. 请注意,上面的字符串不是双引号。

I want to display the String as it is, but for some reason its not processing and i am not able to proceed further. 我想按原样显示String,但是由于某种原因,它无法处理,因此我无法继续进行操作。

What is the best way to encode this ? 编码的最佳方法是什么?

I have tried the below : 我尝试了以下方法:

String out = null;
        try {
            out = new String(s.getBytes("UTF-8"), "ISO-8859-1");
        } catch (java.io.UnsupportedEncodingException e) {
            return null;
        }
        return out;

But it adds some special symbols to the specials chars. 但这会在特殊字符中添加一些特殊符号。

I am trying to add this string in paypal payment screen , where we display item name. 我正在尝试在显示项目名称的贝宝付款屏幕中添加此字符串。

试试这个,它可能对您有帮助,

tv.settext(Html.fromHtml("Your Text"));

看一下Apache Commons中的StringEscapeUtils.escapeJava之类的东西

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM