- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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:
And my code within the script to get this set string object into multiple strings currently looks like this:
How would I go about accomplishing this? Thanks everyone.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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).
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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).
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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);
);