Subscribe Bookmark RSS Feed

Transposing a comma-separated string into a column in JSL

davidk

Community Trekker

Joined:

Jan 29, 2013

Hi folks,

I am want to transform a string that i am getting as an input from a text edit box such as a,b,c,d... into a column:

a

b

c

d

...

Any ideas?

Thanks,

David

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

You can use the WORDS function to parse the string into a list, and then add it as a new column.

a = words("a,b,c,d,e", ",");

n = nitems(a);

dt = new table("Untitled", add rows(n),

        new column("My List", character, nominal, set values(a)));

4 REPLIES
Solution

You can use the WORDS function to parse the string into a list, and then add it as a new column.

a = words("a,b,c,d,e", ",");

n = nitems(a);

dt = new table("Untitled", add rows(n),

        new column("My List", character, nominal, set values(a)));

davidk

Community Trekker

Joined:

Jan 29, 2013

This is exactly what i was looking for, thanks a bunch!

Unfortunately, i cannot make the next step which i thought to be trivial.

How can the column you called "My List" be saved as a text file? I used various combinations with the command save text file, but nothing worked. This is the only column in the data table, so saving the whole table would work as well.

pmroz

Super User

Joined:

Jun 23, 2011

If all you want to do is save each entry in your original string into a separate line of a file, then there's a simpler way:

a = "a,b,c,d,e";

crlf = hextochar("0D") || hextochar("0A");

b = substitute(a, ",", crlf);

save text file("C:\b.txt", b);

davidk

Community Trekker

Joined:

Jan 29, 2013

Many thanks