1

我有一个Q 编码的字符串变量:

String s = "=?ISO-8859-1?Q?Merve_G=FCl?=";

我想用真正的角色在屏幕上写它:“Merve Gül”。

我怎样才能做到这一点?

@缺口

String string = "=?ISO-8859-1?Q?Merve_G=FCl?=";
QCodec q = new QCodec();
        try 
        {
            q.decode(string);
            System.out.println(q.decode(kimdenIsim));
        } catch (DecoderException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 

我收到此错误:

05-08 11:22:39.287: W/System.err(1142): org.apache.commons.codec.DecoderException: RFC 1522 violation: malformed encoded content
05-08 11:22:40.448: W/System.err(1142):     at org.apache.commons.codec.net.RFC1522Codec.decodeText(RFC1522Codec.java:102)
05-08 11:22:40.448: W/System.err(1142):     at org.apache.commons.codec.net.QCodec.decode(QCodec.java:230)
05-08 11:22:40.457: W/System.err(1142):     at com.mobil.eposta.GoruntuleActivity.EksizPosta(GoruntuleActivity.java:138)
05-08 11:22:40.457: W/System.err(1142):     at com.mobil.eposta.GoruntuleActivity.onCreate(GoruntuleActivity.java:52)
05-08 11:22:40.477: W/System.err(1142):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-08 11:22:40.477: W/System.err(1142):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-08 11:22:40.477: W/System.err(1142):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-08 11:22:40.497: W/System.err(1142):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-08 11:22:40.497: W/System.err(1142):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-08 11:22:40.507: W/System.err(1142):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-08 11:22:40.517: W/System.err(1142):     at android.os.Looper.loop(Looper.java:123)
05-08 11:22:40.517: W/System.err(1142):     at android.app.ActivityThread.main(ActivityThread.java:4627)
05-08 11:22:40.517: W/System.err(1142):     at java.lang.reflect.Method.invokeNative(Native Method)
05-08 11:22:40.517: W/System.err(1142):     at java.lang.reflect.Method.invoke(Method.java:521)
05-08 11:22:40.517: W/System.err(1142):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-08 11:22:40.537: W/System.err(1142):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-08 11:22:40.537: W/System.err(1142):     at dalvik.system.NativeStart.main(Native Method)

第 4 个错误行显示:q.decode(string);

4

3 回答 3

2

根据这个答案是否有可能这样。为此,您需要 JavaMail。我刚刚测试成功。

import javax.mail.internet.MimeUtility;

String s = "=?ISO-8859-1?Q?Merve_G=FCl?=";
String string = MimeUtility.decodeText(s);
于 2014-07-30T10:56:39.840 回答
1

Apache Commons Codec有一个QCodec类来解码这种格式。只需将库添加到您的项目中。

//String s must start with "=?" and end with "?="
QCodec q = new QCodec();
q.decode(s);
于 2012-05-08T11:14:09.843 回答
-2

试试这个代码

try {
    // Convert from Unicode to UTF-8
    String string = "abc\u5639\u563b";
    byte[] utf8 = string.getBytes("UTF-8");

    // Convert from UTF-8 to Unicode
    string = new String(utf8, "UTF-8");
} catch (UnsupportedEncodingException e) {
}
于 2012-05-08T10:57:24.423 回答