JAVA中如何去除字符串前后的全角空格(当中保留)(轉)

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

public static void main(String[] args) {
    String a = "   aaaa aaaa   ";
    a = a.trim();
    while(a.startsWith(" ")){
       a = a.substring(1,a.length()).trim();
    }
    while(a.endsWith(" ")){
       a = a.substring(0,a.length()-1).trim();
    }
    System.out.println(a);
  }

转载于:https://my.oschina.net/dddgggaaa/blog/204937

你可能感兴趣的:(java,python)