用16进制ASCII码作分隔符

public class TestStrChar {
    //ASCII码 16进制
    //平时在拼接字符串的时候是不是采用","或":"等特殊字符作分隔符
    //这样做有的时候不很安全,因为你不能确保你传入的字符串中没有这几个字符
    //ASCII码为0x01,0x02的字符是键盘所不能输入的,因此用这个能保证万无一失。
    public static final String F_STRING = new String(new char[]{0x01});
    
    public static void main(String[] args) {
        
        System.out.println("F_STRING : " +F_STRING);//F_STRING :         
        String ssString = "123"+ F_STRING + "321";
        System.out.println("ssString: "+ssString);//ssString: 123321
        String[] strs = ssString.split(F_STRING);
        for(int i=0;i<strs.length;i++){
            System.out.println(strs[i].toString());// 依次打印:123,321
        }
    }

}

 

相关文章:

  • 2021-11-17
  • 2021-12-09
  • 2022-12-23
  • 2021-09-01
  • 2021-10-03
  • 2022-12-23
  • 2021-10-29
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-30
  • 2022-12-23
相关资源
相似解决方案