java中的spilt()特殊情况和多个分割符
特殊情况有 * ^ : | . \
一、单个符号作为分隔符
- String address="上海\上海市|闵行区\吴中路";
String[] splitAddress=address.split("\\"); System.out.println(splitAddress[0]+splitAddress[1]+splitAddress[2]+splitAddress[3]);
- String address="上海|上海市|闵行区|吴中路";
String[] splitAddress=address.split("\\|"); //如果以竖线为分隔符,则split的时候需要加上两个斜杠【\\】进行转义 System.out.println(splitAddress[0]+splitAddress[1]+splitAddress[2]+splitAddress[3]);
- String address="上海*上海市*闵行区*吴中路";
String[] splitAddress=address.split("\\*"); System.out.println(splitAddress[0]+splitAddress[1]+splitAddress[2]+splitAddress[3]);
- String address="上海:上海市:闵行区:吴中路";
String[] splitAddress=address.split("\\:"); System.out.println(splitAddress[0]+splitAddress[1]+splitAddress[2]+splitAddress[3]);
- String address="上海.上海市.闵行区.吴中路";
String[] splitAddress=address.split("\\."); System.out.println(splitAddress[0]+splitAddress[1]+splitAddress[2]+splitAddress[3]);
- String address="上海^上海市^闵行区^吴中路";
String[] splitAddress=address.split("\\^"); System.out.println(splitAddress[0]+splitAddress[1]+splitAddress[2]+splitAddress[3]);
现在的几乎什么都不懂,但是不代表以后的我也是这样。