「Google Apps Script」trimメソッドで先頭と末尾の空白を取り除く

構文
文字列.trim()
文字列の先頭と末尾の半角空白を取り除きます。
先頭と末尾以外にある空白は取り除きません

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function myFunction() {
// 半角空白あり
const strA = " test 88 ";
console.log(strA.trim());
// 全角空白あり
const strB = " test 99 ";
console.log(strB.trim());
}
function myFunction() { // 半角空白あり const strA = " test 88 "; console.log(strA.trim()); // 全角空白あり const strB = " test 99 "; console.log(strB.trim()); }
function myFunction() {
  // 半角空白あり
  const strA = " test 88  "; 
  console.log(strA.trim()); 

  // 全角空白あり
  const strB = " test 99 ";
  console.log(strB.trim()); 
}

実行結果
test 88
test 99

Google Apps Script

Posted by arkgame