[[
split
]]
Xtal Unofficial Wiki
現在位置:
Xtal Unofficial Wiki
»
Xtal Reference
»
String
»
split
文書の表示
以前のリビジョン
最近の変更
サイトマップ
ログイン
この文書は読取専用です。文書のソースを閲覧することは可能ですが、変更はできません。もし変更したい場合は管理者に連絡してください。
====== split ====== ===== C++ ===== <code cpp> // param type : String, xpeg::Element // return type : Iterator AnyPtr String::split(const AnyPtr& pattern) const; </code> ===== Xtal ===== <code cpp> // param type : String, xpeg::Element // return type : Fiber String::split : method(pattern); </code> ===== Description ===== //pattern//に与えたパターンで文字列を分割します。パターンには文字列の他、数値範囲、文字範囲など、XPEGの要素に変換可能な型ならば様々渡すことができます。 分割された断片が空文字になった際も取り除かれません。 C++ではIteratorを返し、XtalではFiberを返すので、結果の処理の仕方が少々異なることもありますが、[[..:Iterator]]クラスのメソッドを使う場合は同じように処理できます。 ===== Example1 ===== スペースで文字列を分割する ==== C++ ==== ==== Xtal ==== <code cpp> str : "10 20 30 40 50"; pattern : " "; splitedIter : str.split(pattern); // iterator[]は、Iteratorの派生クラスにおいて有効で、イテレート要素を配列に変換する //splitedIter[].p; list : splitedIter.filter(|x| x!="")[]; list.p; </code> ==== Output ==== <code> [10, 20, 30, 40, 50] </code> ===== Example2 ===== スペースまたはカンマで文字列を分割する ==== C++ ==== ==== Xtal ==== <code cpp> str : "10,20 30 , 40, 50"; // pattern : " " | ","; // 本来うまくいくはずだが、ライブラリがtypoってて動かない pattern : xpeg::set(" ,"); splitedIter : str.split(pattern); list : splitedIter.filter(|x| x!="")[]; list.p; </code> ==== Output ==== <code> [10, 20, 30, 40, 50] </code> ===== See Also ===== * [[..:xpeg]] * [[..:Iterator]]
reference/string/split.txt · 最終更新: 2011/07/04 15:15 by sukai
文書の表示
以前のリビジョン
文書の先頭へ