StrToStringsを使うには、JclStrings.hppをincludeします。
#include <JclStrings.hpp>
※AnsiString版を使うときはJclAnsiStrings.hppを使用します。
#include <JclAnsiStrings.hpp>
StrToStringsの定義は次のようになります。
extern PACKAGE void __fastcall StrToStrings(
System::UnicodeString S,
System::UnicodeString Sep,
System::Classes::TStrings* const List,
const bool AllowEmptyString = true);
引数Sは分割する文字列、引数Sepは区切り文字、引数Listは分割した文字列を登録するリストです。
引数AllowEmptyStringがfalseのときは空文字は結果から除外されます。
サンプルプログラム1
//分割する文字列
UnicodeString S = "イージス|バスター|デュエル|ブリッツ|ストライク";
//区切り文字
UnicodeString Sep = "|";
//分割した文字列のリスト
TStringList* List = new TStringList();
StrToStrings(S, Sep, List);
Memo1->Lines->Assign(List);
サンプルプログラム2(AllowEmptyStringの比較)
//分割する文字列
UnicodeString S = "イージス||バスター||||デュエル|ブリッツ|ストライク";
//区切り文字
UnicodeString Sep = "|";
//分割した文字列のリスト
TStringList* List = new TStringList();
//AllowEmptyStringがtrueのとき
StrToStrings(S, Sep, List, true);
Memo1->Lines->Assign(List);
//AllowEmptyStringがfalseのとき
StrToStrings(S, Sep, List, false);
Memo2->Lines->Assign(List);