- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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 );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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 );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: JSL to loop words in a list
Thanks PMroz....that worked for me!!