string split
String string = "004-034556";
String[] parts = string.split("-");
String part1 = parts[0]; // 004
String part2 = parts[1]; // 034556
Note that this takes a
regular expression
, so remember to escape special characters if necessary, e.g. if you want to split on period
.
which means "any character" in regex, use either
split("\\.")
or
split(Pattern.quote("."))
.
注意特殊字符要用\\
这个题要注意每次比较要转化成int再比 因为可能会有01与1比较的情况。同时会有1.0与1 所以最后只比较长度不够。