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

Separating string copied directly from data table using Words()

To use a script I'm currently working on, I need to copy-paste a set of cells from a data-table column (multiple rows, one column) into a text edit box (this step is done by the user), and within the script, I want to store this set of character cells into a single string object and separate this string out into constituent strings using the Words() function. However, when I copy directly from the data-table to the clipboard for pasting, the resultant object, when converted to a string doesn't seem to separate cell contents by either a space " " or a newline character "\!n", which would prove problematic in effective use of the Words() function to separate it out. For example, such a set of cells directly copy-pasted from a data table into the text box would look like this:

Screen Shot 2022-01-16 at 12.52.25 AM.png

And my code within the script to get this set string object into multiple strings currently looks like this:

Screen Shot 2022-01-16 at 12.56.32 AM.png

How would I go about accomplishing this? Thanks everyone.

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Separating string copied directly from data table using Words()

You seem to have \!n instead of \!N.

 

For me it seems to work fine with this example (using Windows and JMP16).

jthi_0-1642323918193.png

 

jthi_1-1642323923109.png

 

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");

nw = New Window("a",
	teb = Text Edit Box("", << Set N Lines(20))
);

//paste values to teb...
//get values
teb_values = teb << get text;
teb_as_list = Words(teb_values, "\!N");
Show(teb_as_list);
//{"KATIE", "LOUISE", "JANE", "JACLYN", "LILLIE", "TIM", "JAMES", "ROBERT", "BARBARA",
//"ALICE", "SUSAN", "JOHN", "JOE", "MICHAEL"}

Also copy-pasting from JMP datatable to Notepad++ with "View all characters" enabled, CR (Carrier Return) and LF (Line Feed) seem to be added at the end of row/line:

jthi_2-1642323947334.png

 

-Jarmo

View solution in original post

5 REPLIES 5
jthi
Super User

Re: Separating string copied directly from data table using Words()

You seem to have \!n instead of \!N.

 

For me it seems to work fine with this example (using Windows and JMP16).

jthi_0-1642323918193.png

 

jthi_1-1642323923109.png

 

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");

nw = New Window("a",
	teb = Text Edit Box("", << Set N Lines(20))
);

//paste values to teb...
//get values
teb_values = teb << get text;
teb_as_list = Words(teb_values, "\!N");
Show(teb_as_list);
//{"KATIE", "LOUISE", "JANE", "JACLYN", "LILLIE", "TIM", "JAMES", "ROBERT", "BARBARA",
//"ALICE", "SUSAN", "JOHN", "JOE", "MICHAEL"}

Also copy-pasting from JMP datatable to Notepad++ with "View all characters" enabled, CR (Carrier Return) and LF (Line Feed) seem to be added at the end of row/line:

jthi_2-1642323947334.png

 

-Jarmo
akfence
Level II

Re: Separating string copied directly from data table using Words()

Hi jthi,

 

Thank you for this. I'm using JMP 15, so the version is an issue maybe? Also, how would I specify a carrier return or line feed character in something like the Words() function? Thank you again.

 

txnelson
Super User

Re: Separating string copied directly from data table using Words()

I have validated @jthi findings in JMP 15.  The variable "teb_values" contains the text from the Text Edit Box(), with a carriage return, "0D" and a line feed character, "0A" between each line.

 

I am running on a Windows 10 system.

Jim
jthi
Super User

Re: Separating string copied directly from data table using Words()

I would suggest printing all the variables with Show() to JMP's log to see what goes wrong. Also checkout Escape Sequences for Quoted Strings , in most of the cases \!N should be enough

-Jarmo
pmroz
Super User

Re: Separating string copied directly from data table using Words()

Are the users selecting rows in the table?  If so this code will yield a list without needing to parse anything.

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");

// Mimic the user selecting some rows
dt << select where (:name == "KATIE" | :name == "JANE" | :name == "JOE");

user_rows = dt << get selected rows();

if (nrows(user_rows) > 0,
	name_list = dt:name[user_rows];
	show(name_list);
);