cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
WanCine
Level II

Split Array

Hi,

 

1. Any ideas how to split a = {"c", "d","e"}; into a= {"c"}, {"d"},{"e"}; ? Currently when I did Concat Items (a, ","); , the output will be "c,d,e" instead of "c","d","e" .

 

2. Concat Items did apply after letter c. However, what if I want to concat "," before c such as ",c,d,e"?

 

3. Is there any possibilities to combine semicolon together with other strings? For example, " " "|| water || bend || "," || " " " , thus the output will be "water bend,"

2 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: Split Array

That would be read same as if you "removed" first quotes (as it is string) and replaced all \!" with single ".

 

Check log after running this script (and also created datatable, it will add a_string value to one cell)

 

Names Default To Here(1);

a_list =  {"c", "d", "e"};
show(a_list);
a_string = "\!"" || Concat Items(a_list, "\!",\!"") || "\!"";
show(a_string);
write("\!NWrite print: "||a_string);

dt = New Table("newtable",
	Add Rows(1),
	Compress File When Saved(1),
	New Column("col", Character, "Nominal", Set Values({""}))
);

column(dt, "col") << Set Each Value(a_string);
write();

 

 

 

 

 

I have had my challenges with strings in JMP and it has depended on the use case what I have had to do to manage with them to add quotes.

 

-Jarmo

View solution in original post

Jeff_Perkinson
Community Manager Community Manager

Re: Split Array


@WanCine wrote:

Hi,

 

1. Any ideas how to split a = {"c", "d","e"}; into a= {"c"}, {"d"},{"e"}; ? Currently when I did Concat Items (a, ","); , the output will be "c,d,e" instead of "c","d","e" .

I'm having trouble making sense of this question because a= {"c"}, {"d"},{"e"}; isn't valid JSL. There's no data structure which will hold three separate lists like that. Can you clarify exactly what you're trying to do?


2. Concat Items did apply after letter c. However, what if I want to concat "," before c such as ",c,d,e"?

Try this:

 

a = {"c", "d", "e"};

z = "," || Concat Items( a, "," );

3. Is there any possibilities to combine semicolon together with other strings? For example, " " "|| water || bend || "," || " " " , thus the output will be "water bend,"

I think @jthi pointed out that you can escape quotation marks with \!".

 

foo = " \!" "|| "water " || "bend" || "," || " \!" ";

 

 

-Jeff

View solution in original post

4 REPLIES 4
jthi
Super User

Re: Split Array

You can escape quotes with \!"

 

Names Default To Here(1);

a =  {"c", "d", "e"};
a = "\!"" || Concat Items(a, "\!",\!"") || "\!"";
write(a);

Also check out https://www.jmp.com/support/help/en/15.2/index.shtml#page/jmp/jsl-syntax-rules.shtml

-Jarmo
WanCine
Level II

Re: Split Array

Hi Jthi,

 

Thanks for the reply. I believe your reply refer to question no.3 only. I did try that \!" earlier. But when check the return value, it shown as below figure. So, this return value should be read as "c, d, e" and not as per shown below. Correct me if I am wrong.

WanCine_0-1610569851429.png

 

jthi
Super User

Re: Split Array

That would be read same as if you "removed" first quotes (as it is string) and replaced all \!" with single ".

 

Check log after running this script (and also created datatable, it will add a_string value to one cell)

 

Names Default To Here(1);

a_list =  {"c", "d", "e"};
show(a_list);
a_string = "\!"" || Concat Items(a_list, "\!",\!"") || "\!"";
show(a_string);
write("\!NWrite print: "||a_string);

dt = New Table("newtable",
	Add Rows(1),
	Compress File When Saved(1),
	New Column("col", Character, "Nominal", Set Values({""}))
);

column(dt, "col") << Set Each Value(a_string);
write();

 

 

 

 

 

I have had my challenges with strings in JMP and it has depended on the use case what I have had to do to manage with them to add quotes.

 

-Jarmo
Jeff_Perkinson
Community Manager Community Manager

Re: Split Array


@WanCine wrote:

Hi,

 

1. Any ideas how to split a = {"c", "d","e"}; into a= {"c"}, {"d"},{"e"}; ? Currently when I did Concat Items (a, ","); , the output will be "c,d,e" instead of "c","d","e" .

I'm having trouble making sense of this question because a= {"c"}, {"d"},{"e"}; isn't valid JSL. There's no data structure which will hold three separate lists like that. Can you clarify exactly what you're trying to do?


2. Concat Items did apply after letter c. However, what if I want to concat "," before c such as ",c,d,e"?

Try this:

 

a = {"c", "d", "e"};

z = "," || Concat Items( a, "," );

3. Is there any possibilities to combine semicolon together with other strings? For example, " " "|| water || bend || "," || " " " , thus the output will be "water bend,"

I think @jthi pointed out that you can escape quotation marks with \!".

 

foo = " \!" "|| "water " || "bend" || "," || " \!" ";

 

 

-Jeff