有過濾你所需要的特殊字符的方式。只是檢查ASCII表
希望它可以幫助
public class main {
public static void main(String args[]) {
String str = args[0];
String bstr = "";
String[] codePointAt = new String[str.length()];
if (str != "")
{
for (int j = 0; j < str.length(); j++)
{
int charactercode=Character.codePointAt(str, j);
//CHECK on ASCII TABLE THE SPECIAL CHARS YOU NEED
if( (charactercode>31 && charactercode<48) ||
(charactercode>57 && charactercode<65) ||
(charactercode>90 && charactercode<97) ||
(charactercode>127)
)
{
codePointAt[ j] ="&"+String.valueOf(charactercode)+";";
}
else
{
codePointAt[ j] = String.valueOf(str.charAt(j));
}
}
for (int j = 0; j < codePointAt.length; j++)
{
System.out.println("CODE "+j+" ->"+ codePointAt[j]);
}
}
}
}
輸出
call with ("TRY./&asda")
CODE 0 ->T
CODE 1 ->R
CODE 2 ->Y
CODE 3 ->&46;
CODE 4 ->&47;
CODE 5 ->&38;
CODE 6 ->a
CODE 7 ->s
CODE 8 ->d
CODE 9 ->a
檢查這個http://stackoverflow.com/questions/2220366/get-unicode-value-of- a-character –
哇合法擁有'java'和'javascript'標記的問題! – jbabey
誰告訴你_Unicode是24位_? – jlordo