十六進制字符串每隔32個字母換行顯示

 

//每32個字節換行打印 
public static void formatPrint(String hexStr){ 
  int no = 0; 
  int length = hexStr.length(); 
  for (int i=0;i<length;i++){ 
   if ((i+1)%32==0){ 
    String s = twoSpaceTwo(hexStr.substring(i - 31, i + 1)); 
System.out.println("no"+no+":"+s); no++; if (length-i<32){
return; } } } }

 

//隔兩位打印一個空格----正則表達式方法 
public static String twoSpaceTwo(String replace){ 
  String regex = "(.{2})"; 
  replace = replace.replaceAll(regex, "$1 "); 
  return replace; 
}

 

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