こんにちは、
文字列をリストに変換する組み込み関数はありますか? たとえば、文字列「abcd1234cdef5678」があり、それを {"abcd", "1234", "cdef, "5678""} に変換したいとします。
ありがとう!
アフマド
別のテクニック:
parts = {};
rc = Pat Match( "1234567890abcdefghijklmnopqrstuv", Pat Repeat( Pat Len( 4 ) >> parts[N Items( parts ) + 1] ) );
Show( parts );
パーツ = {"1234"、"5678"、"90ab"、"cdef"、"ghij"、"klmn"、"opqr"、"stuv"};
Jim のアプローチは、次に JSL を保守する人が理解できるため、短い文字列の場合に適しています。 10K 程度の文字列の場合、パターン マッチングが著しく高速になります。
The pattern match (red curve) avoids reprocessing the stringThe pattern match (red curve) avoids reprocessing the stringThe pattern match (red curve) avoids reprocessing the stringThe pattern match (red curve) avoids reprocessing the stringThe pattern match (red curve) avoids reprocessing the stringThe pattern match (red curve) avoids reprocessing the stringパターン一致 (赤い曲線) により、文字列の再処理が回避されます。
グラフを作成するための JSL です...
dt = New Table( "Untitled",
Add Rows( 0 ),
New Column( "n", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [] ) ),
New Column( "forloopTime", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [] ) ),
New Column( "patternTime", Numeric, "Continuous", Format( "Best", 12 ), Set Selected, Set Values( [] ) )
);
For( nstr = 1, nstr < 10000, nstr *= 2,
dt << addrows( 1 );
dt:n = nstr * 4; // four substrings in the repeat...
TheString = Repeat( "abcd1234cdef5678", nstr );
start = Tick Seconds();
TheList = {};
i = 1;
While( Substr( TheString, i, 4 ) != "",
Insert Into( TheList, Substr( TheString, i, 4 ) );
i = i + 4;
);
stop = Tick Seconds();
dt:forloopTime = (stop - start);
start = Tick Seconds();
parts = {};
rc = Pat Match( theString, Pat Repeat( Pat Len( 4 ) >> parts[N Items( parts ) + 1] ) );
stop = Tick Seconds();
dt:patternTime = (stop - start);
Wait( 0 );
);
dt << Graph Builder(
Size( 764, 624 ),
Show Control Panel( 0 ),
Legend Position( "Inside Left" ),
Variables( X( :n ), Y( :forloopTime ), Y( :patternTime, Position( 1 ) ) ),
Elements( Points( X, Y( 1 ), Y( 2 ), Legend( 9 ) ), Smoother( X, Y( 1 ), Y( 2 ), Legend( 10 ) ) ),
SendToReport(
Dispatch( {}, "n", ScaleBox, {Min( -1453.48837209302 )} ),
Dispatch( {}, "forloopTime", ScaleBox, {Format( "Best", 12 ), Min( -0.949803149606299 )} ),
Dispatch( {}, "graph title", TextEditBox, {Set Text( "Compare algorithms" )} ),
Dispatch( {}, "X title", TextEditBox, {Set Text( "n patterns " )} ),
Dispatch( {}, "Y title", TextEditBox, {Set Text( "Seconds" )} ),
Dispatch( {}, "400", LegendBox, {Set Title( "" )} )
)
);
for ループの例が大きな文字列で遅くなる理由: substr 関数は、次の場所を見つける必要があります。各から始まる部分文字列始まり。 パターンマッチは文字列内を移動します一度。
そのような関数は知りませんが、このコードを使用するか、関数にすることができます
Names Default To Here( 1 );
TheString = "abcd1234cdef5678";
TheList = {};
i = 1;
While( Substr( TheString, i, 4 ) != "",
Insert Into( TheList, Substr( TheString, i, 4 ) );
i = i + 4;
);
</CODE></PRE>
<P>または、関数としてここにあります</P>
<PRE><CODE class=" language-jsl">SeparateString = Function( {TheString},
TheList = {};
i = 1;
While( Substr( TheString, i, 4 ) != "",
Insert Into( TheList, Substr( TheString, i, 4 ) );
i = i + 4;
);
TheList;
);
MyList = SeparateString("abcd1234cdef5678");
こんにちは、ジムさん
文字列があり、文字列の区切りをカンマで終了したい場合、どのようにアプローチしますか。
例えば、
これを " C = "今日は雨が降っていて、とても、大変です" を b = {"雨が降っています" 、"とても"、"今日は大変です" } に変換します。
ありがとう!
アップデート:
これに関する古いスレッドを見つけました ジェフ・パーキンソン。
これはリンクです解決済み: Words 機能の区切り文字として複数の文字を使用する - JMP ユーザー コミュニティ
私にとってうまくいった解決策は、次の方法を使用することでした。
words(substitute("Test1eeTest2", "ee", "!"),"!")
/*:
{"Test1", "Test2"}
<BR />ありがとう。
-友達
Words() 関数を使用して、指定された区切り文字 (この場合はカンマ) で識別される各部分文字列の要素を含む文字列をリストに分割します。
names default to here(1);
C = "It is, raining, very, hard today";
b = Words( C, "," );
文字列を単一文字のリストに変換する場合 (OP の要求とは少し異なりますが、タイトルと一致します)、次のように実行できます。
Items( "hello", "" );
結果は次のようになります:
{"h", "e", "l", "l", "o"}