處理String特殊符號

半角轉化全角

public static String toDBC(String str){
    char[] c=str.toCharArray();
    for(int i=0;i<c.length();i++){
        if(c[i]==12288){
            c[i]=(char)32;
            continue;
        }
        if(c[i]>65280&&c[i]<65375)
            c[i]=(char)(c[i]-65248);
    }
}

去除特殊字符或將所有中文標號替換爲英文標號

public static String stringFilter(String str){
    str = str.replaceAll("【","[")
             .replaceAll("】","]") 
             .replaceAll("!","!")
             .replaceAll(":",":");// 替換中文標號 
    String regEx = "[『』]";// 清除掉特殊字符 
    Pattern p = Pattern.compile(regEx); 
    Matcher m = p.matcher(str); 
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章