안녕하세요,
문자열을 목록으로 변환하는 내장 함수가 있습니까? 예를 들어 문자열 "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 = {"오늘은" , "비가 내린다" , "매우", "오늘은 힘들다" }
감사해요!
업데이트:
나는 이것에 대한 오래된 스레드를 찾았습니다. Jeff_Perkinson.
해결된 링크입니다: 단어 기능에 대한 구분 기호로 여러 문자 사용 - JMP User Community
나에게 도움이 된 솔루션은 다음 방법을 사용하는 것입니다.
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"}