Prototype-string-gsub

提供:Dev Guides
移動先:案内検索

プロトタイプ-gsub()メソッド

このメソッドは、特定のパターンが出現するたびに、通常の文字列、関数の戻り値、またはテンプレート文字列のいずれかに置き換えられた文字列を返します。 パターンには、文字列または正規表現を使用できます。

構文

string.gsub(pattern, replacement);

戻り値

文字列を返します。

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>

      <script>
         function showResult() {
            var mouseEvents = 'click dblclick mousedown';
            alert( "mouseEvents :" + mouseEvents.gsub(/\s+/, ', ') );
         }
      </script>
   </head>

   <body>
      <p>Click the button to see the result.</p>
      <br/>
      <br/>
      <input type = "button" value = "Result" onclick = "showResult();"/>
   </body>
</html>

出力