Java判斷不可打印字符,類似C語言的isprint() 函數



publicstatic String isprint(String str){
         
         if(StringUtils.isEmpty(str)){
             return"";
         }
          
         byte[] bts =str.getBytes();
         intbtsLength= bts.length;
         byte[] newBytes = newbyte[btsLength];
         for(inti =0;i<btsLength;i++) {
              
            byteb =bts[i]; 
            if((b >=0&& b <=31) || b >=127){
//將不可打印字符至空
                 b =32;
            }
             
            newBytes[i]=b;
        }
          
        returnnew String(newBytes);
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章