Subscribe Bookmark RSS Feed

JSL to loop words in a list

mward

Community Trekker

Joined:

Nov 1, 2012

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

Joined:

Jun 23, 2011

Solution

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 );

4 REPLIES
ms

Super User

Joined:

Jun 23, 2011

Solution

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

Community Trekker

Joined:

Oct 23, 2014

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

Joined:

Jun 23, 2011

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

Community Trekker

Joined:

Oct 23, 2014

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