当前位置: 技术问答>java相关
请问 怎样才能得到一个字符串的编码方式?
来源: 互联网 发布时间:2015-06-26
本文导语: Subject: =?GB2312?B?1tDOxEphdmG8vMr1zfijurXazuXG2g==?= Subject: =?gb2312?b?enk3ODdAMjFjbi5jb20tLS0tdGVzdCAg1tC27aGizsI=?= Subject:CSDN账号密码修改 怎样才能得到这个字符串( Subject )的编码方式? | 经典代码: /*...
Subject: =?GB2312?B?1tDOxEphdmG8vMr1zfijurXazuXG2g==?=
Subject: =?gb2312?b?enk3ODdAMjFjbi5jb20tLS0tdGVzdCAg1tC27aGizsI=?=
Subject:CSDN账号密码修改
怎样才能得到这个字符串( Subject )的编码方式?
Subject: =?gb2312?b?enk3ODdAMjFjbi5jb20tLS0tdGVzdCAg1tC27aGizsI=?=
Subject:CSDN账号密码修改
怎样才能得到这个字符串( Subject )的编码方式?
|
经典代码:
/**
* 返回字符集名
*/
public static String getCharSet(String eword) {
if (!eword.startsWith("=?")) // not an encoded word
return null;
// get charset
int start = 2; int pos;
if ((pos = eword.indexOf('?', start)) == -1)
return null;
return javax.mail.internet.MimeUtility.javaCharset(eword.substring(start, pos));
}
/**
* 返回编码形式
*/
public static String getEncoding(String eword) {
if (!eword.startsWith("=?")) // not an encoded word
return null;
int start = 2; int pos;
if ((pos = eword.indexOf('?', start)) == -1)
return null;
// get encoding
start = pos+1;
if ((pos = eword.indexOf('?', start)) == -1)
return null;
return eword.substring(start, pos);
}
/**
* 返回字符集名
*/
public static String getCharSet(String eword) {
if (!eword.startsWith("=?")) // not an encoded word
return null;
// get charset
int start = 2; int pos;
if ((pos = eword.indexOf('?', start)) == -1)
return null;
return javax.mail.internet.MimeUtility.javaCharset(eword.substring(start, pos));
}
/**
* 返回编码形式
*/
public static String getEncoding(String eword) {
if (!eword.startsWith("=?")) // not an encoded word
return null;
int start = 2; int pos;
if ((pos = eword.indexOf('?', start)) == -1)
return null;
// get encoding
start = pos+1;
if ((pos = eword.indexOf('?', start)) == -1)
return null;
return eword.substring(start, pos);
}