cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Discovery is online this week, April 16 and 18. Join us for these exciting interactive sessions.
Choose Language Hide Translation Bar
mward
Level I

JSL to loop words in a list

Hey guys,

I have a really basic JSL question, I hope.

I'm using this line to create a list of words in a string.

all_list = words(first_string, " ");

I then want to loop all the words in all_list and get rid of any words that are a length of three or less.

How do I set up that loop?

Thanks in advance!

Matt

1 ACCEPTED SOLUTION

Accepted Solutions
ms
Super User (Alumni) ms
Super User (Alumni)

Re: JSL to loop words in a list

One approach is to use the Remove From() function in a reversed loop, i.e. removing items from the end of the list to preserve the list item numbering.

first_string =

"Change the scale of a plot by clicking in the frame with the Magnifier tool or by rescaling the axes";

all_list = Words( first_string, " " );

For( i = N Items( all_list ), i > 0, i--,

  If( Length( all_list[i] ) <= 3,

  Remove From( all_list, i, 1 )

  )

);

Show( all_list );

View solution in original post

4 REPLIES 4
ms
Super User (Alumni) ms
Super User (Alumni)

Re: JSL to loop words in a list

One approach is to use the Remove From() function in a reversed loop, i.e. removing items from the end of the list to preserve the list item numbering.

first_string =

"Change the scale of a plot by clicking in the frame with the Magnifier tool or by rescaling the axes";

all_list = Words( first_string, " " );

For( i = N Items( all_list ), i > 0, i--,

  If( Length( all_list[i] ) <= 3,

  Remove From( all_list, i, 1 )

  )

);

Show( all_list );

nnk
nnk
Level I

Re: JSL to loop words in a list

Just trying to ask a related question....how can one save a list into a data table OR text file? I have looked through the JSL scripting guide and have not come across any functions to convert a list to data table. Any help is appreciated!

pmroz
Super User

Re: JSL to loop words in a list

The scripting index is helpful in this regard.  To set values in a column in a table:

column(dt, "My Column Name") << set values(all_list);

To save a list to a text file:

save text file("c:\temp\myfile.txt", char(all_list));

// To save each entry on its own line:

all_text = concat items(all_list, "

");

save text file("c:\temp\myfile.txt", all_text);

nnk
nnk
Level I

Re: JSL to loop words in a list

Thanks PMroz....that worked for me!!