How cna use JSL statistics to specify the frequency of characters in a memory variable?For example,
If the specified character exists, and calculates each position of the character in TXT.
txt="1ab34cab4abba";
t0="ab";
x=3;//"ab"appears three times in TXT——??X=N Rows(Loc(txt,t0));
m1=2;// The first occurrence of "ab" in TXT is 2
m2=7;// The second occurrence of "ab" in TXT is 7
m3=10;// The third occurrence of "ab" in TXT is 10
How cna use JSL statistics ?
Thanks!
ScriptingRe: How cna use JSL statistics to specify the frequency of characters in a memory variable?Here is a piece of JSL that does your calculation, and creates a JMP List with the results
names default to here(1);
txt="1ab34cab4abba";
t0="ab";
resultList = {0};
target = txt;
while(contains(target,t0),
resultList[1] = resultList[1] + 1;
insert into(resultList,contains(target,t0));
target=substr(target,1,contains(target,t0)-1) || "~~" || substr(target,contains(target,t0)+2);
);
show(resultList);
It returns
resultList = {3, 2, 7, 10};Re: How cna use JSL statistics to specify the frequency of characters in a memory variable?Search a string for all occurrences of a pattern shows a general purpose solution using the pattern matcher. Harder to understand but should have O(N) behavior on large strings.
Re: How cna use JSL statistics to specify the frequency of characters in a memory variable?txt="1ab34cab4abba";
t0="ab";
num=3