在编码字符串中的特殊字符 [英] Encoding Special Characters in String

查看:191
本文介绍了在编码字符串中的特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些特殊字符,像这样的一个字符串。

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.

什么是EN code呢?

What is the best way to encode this ?

我已经试过如下:

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.

推荐答案

看看像<一个href=\"https://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/StringEscapeUtils.html\"相对=nofollow> StringEscapeUtils.escapeJava 来自Apache下议院

have a look at something like StringEscapeUtils.escapeJava from Apache Commons

这篇关于在编码字符串中的特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆