LANG SELRCT

Apps Script Reference  (Create: Create new Spreadsheet | Create new Apps Script

Saturday, February 10, 2018

JavaScriptで文字列の先頭・末尾を取得する


文字列.slice()で先頭と末尾を取得するコードの例です


hello
という文字列の
先頭の h と末尾の o を取得してログに出します




コード.gs
function str_slice(){
  var str = "hello";
  var top = str.slice(0, 1);
  var tail = str.slice(-1);
  Logger.log([top, tail])
}
意訳
この機能がやること
文字列
先頭の文字を取得して
末尾の文字を取得して
ログに出す



参考

Array.prototype.slice()
https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/slice

Latest post

Extracting data from Google Sheets with regular expressions

Introduction Regular expressions are a powerful tool that can be used to extract data from text.  In Google Sheets, regular expressions ca...