LANG SELRCT

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

Tuesday, December 10, 2019

テキストエリア内の特定文字を消したい(.replace(/特定の文字/g, ''))


ピリオド . を消したい

ひらりのテキストエリアに、ピリオド . があれば
削除して右のテキストエリアに表示する





コード.gs
function doGet() {
  return HtmlService.createHtmlOutputFromFile("index");
}
意訳
この機能がやること
指定したHTMLファイルを表示する




index.html
<!DOCTYPE html>
<html>

<head>
    <style>
      textarea {
        width: 30vw;
        height: 90vh;
      }
    </style>
</head>

<body>
  <textarea id="ta"></textarea>
  <textarea id="ta2"></textarea>
<script>

function elem(id) {
  return document.getElementById(id);
}

elem('ta').onkeyup = taKeyup;

function taKeyup() {
  var taValue = elem('ta').value;
  var ta2Value = taValue.replace(/\./g, '');
  elem('ta2').value = ta2Value
}

</script>
</body>
</html>



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...