按点(.)切分,必须要注意转义!如:split("\\.")。
例子:
[java] view plain copy
print?
- public class Test {
- public static void main(String[] args) {
- String s = "adhahd.txt";
- String t[] = s.split("\\.");
- for(int i = 0; i < t.length; i++){
- System.out.println(t[i]);
- }
- }
- }
public class Test { public static void main(String[] args) { String s = "adhahd.txt"; String t[] = s.split("\\."); for(int i = 0; i < t.length; i++){ System.out.println(t[i]); } } }
输出结果:
[html] view plain copy
print?
- adhahd
- txt
时间: 2024-12-16 17:52:39