Javascript下用空白分割字符串,详见:https://blog.terrynow.com/2022/01/07/javascript-split-string-to-array-with-one-or-more-whitespace-or-tabs/
Java下的方法比较简单:
String string = " A B C D E"; String[] parts = string.split("\\s+"); // parts打印出来的是,A,B,C,D,E,也就是说数组第一个是空,我们可以想办法去掉它 System.out.println(String.join(",", parts)); String str = Arrays.stream(parts).filter(item -> item.length()>0).collect(Collectors.joining(",")); // 打印出来是A,B,C,D,E System.out.println(str);
文章评论