[[
gsub
]]
Xtal Unofficial Wiki
現在位置:
Xtal Unofficial Wiki
»
Xtal Reference
»
String
»
gsub
文書の表示
以前のリビジョン
最近の変更
サイトマップ
ログイン
この文書は読取専用です。文書のソースを閲覧することは可能ですが、変更はできません。もし変更したい場合は管理者に連絡してください。
====== gsub ====== ===== C++ ===== <code cpp> StringPtr String::gsub(const AnyPtr& pattern, const AnyPtr& fn) const; </code> ===== Xtal ===== <code cpp> // param1 type : String, ... // param2 type : Stringを返すop_callが定義されている型 // return type : String String::gsub : method(pattern, fn); </code> ===== Description ===== //pattern//に渡したパターンに一致する文字列全てを//fn//(exec)の戻り値で置換します(execはxpeg::Executor)。 最も単純には、文字列//pattern//に一致する文字列全てを文字列//fn//で置き換える、という使い方をします。 置換された文字列がその操作範囲内で再び置換対象になることはありません。 ===== Example1 ===== "foo"を"bar"で置換する ==== C++ ==== ==== Xtal ==== <code cpp> str : "foobar piyo fuga foo"; ptn : "foo"; fn : "bar"; str.gsub(ptn, fn).p; </code> ==== Output ==== <code> barbar piyo fuga bar </code> ===== Example2 ===== "hoge"を"foo"に置換した回数をカウントする ==== C++ ==== - ==== Xtal ==== <code cpp> str : "hogehhhoogehoggehogehohgeohgeogehoegheoghohogeeghhogeeghogeogheohge"; ptn : "hoge"; counter : 0; fn : fun(e){counter++; return "foo";}; str.gsub(ptn, fn).p; counter.p; </code> ==== Output ==== <code> foohhhoogehoggefoohohgeohgeogehoegheoghofooeghfooegfooogheohge 5 </code>
reference/string/gsub.txt · 最終更新: 2011/07/04 15:16 by sukai
文書の表示
以前のリビジョン
文書の先頭へ