「Java」strip関数で先頭と末尾の半角と全角空白を取り除く

環境
Spring Tool Suite 4
JavaSE17
書式
public String strip()
空白が複数の場合、複数の空白を取り除きます。
文字列の先頭と末尾の半角と全角の空白を取り除きます。
先頭と末尾以外にある空白は取り除きません。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
package com.arkgame.study;
public class Stripdemo {
public static void main(String[] args) {
// 半角と全角の空白あり
String strA = "  test +134   ";
String strB = strA.strip();
System.out.println(strB);
System.out.println(strB.length());
}
}
package com.arkgame.study; public class Stripdemo { public static void main(String[] args) { // 半角と全角の空白あり String strA = "  test +134   "; String strB = strA.strip(); System.out.println(strB); System.out.println(strB.length()); } }
package com.arkgame.study;

public class Stripdemo {

      public static void main(String[] args) {
            // 半角と全角の空白あり
            String strA = "  test +134   ";
            String strB = strA.strip();
            
            System.out.println(strB);
            System.out.println(strB.length()); 

      }

}

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
test +134
9
test +134 9
test +134
9

 

Java

Posted by arkgame