Loading

十六进制字符串每隔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; 
}

 

posted @ 2024-04-19 19:11  stono  阅读(11)  评论(0编辑  收藏  举报