cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Learn how to build custom Python data connectors and further customize JMP’s Data Connector Framework with the Python Data Connector Demo, available now in the JMP Marketplace!
  • See how to create experiments to support product design and ID useful product features. Register for June 12 webinar, 2pm US Eastern Time.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
Neo
Neo
Level VI

Can I use Contains () with wildcard?

I have a list as an output from a JSL script. The list is of the form

 

{"John.01.02", "John.01.02 2"," John.01.02 3", "John.01.02 4", "John.01.02 5 Distribution", "John.01.02 6 Distribution", "John.01.02 7 Distribution", "John.01.02 8 - Graph Builder", "John.01.02 9 - Graph Builder", "John.01.02 10 - Graph Builder"}

I want to do an operation if  the word "Distribution" appears in above list and another operation if  the word "Graph Builder" occurs while looping through the items in the list. I am thinking of using the contains() function on the lines of

if (Contains(list, "Distribution"),

,do something);
else do something else.

However, I am unable to select the correct list items within the list and was wondering if I can use a wildcard and write on the lines of 

if (Contains(list, "Distribution*"),

which clearly does not work.

If a wildcard is possible within the contains() function what is the syntax?

If not, how to achieve the operations I am am looking for?

 

When it's too good to be true, it's neither
1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Can I use Contains () with wildcard?

Using Contains() to search through a list, will find only complete matches.  However, searching through a string, using a Contains() it will find strings that have the search criteria anywhere within the string.   So you can get what you want with the method in the following script

Names Default To Here( 1 );
theList = {"John.01.02", "John.01.02 2", " John.01.02 3", "John.01.02 4",
"John.01.02 5 Distribution", "John.01.02 6 Distribution", "John.01.02 7 Distribution",
"John.01.02 8 - Graph Builder", "John.01.02 9 - Graph Builder", "John.01.02 10 - Graph Builder"};
For( i = 1, i <= N Items( theList ), i++,
	If( Contains( theList[i], "Distribution" ),
		Break()
	)
);
If( i <= N Items( theList ),
	Show( theList[i] )
);
Jim

View solution in original post

1 REPLY 1
txnelson
Super User

Re: Can I use Contains () with wildcard?

Using Contains() to search through a list, will find only complete matches.  However, searching through a string, using a Contains() it will find strings that have the search criteria anywhere within the string.   So you can get what you want with the method in the following script

Names Default To Here( 1 );
theList = {"John.01.02", "John.01.02 2", " John.01.02 3", "John.01.02 4",
"John.01.02 5 Distribution", "John.01.02 6 Distribution", "John.01.02 7 Distribution",
"John.01.02 8 - Graph Builder", "John.01.02 9 - Graph Builder", "John.01.02 10 - Graph Builder"};
For( i = 1, i <= N Items( theList ), i++,
	If( Contains( theList[i], "Distribution" ),
		Break()
	)
);
If( i <= N Items( theList ),
	Show( theList[i] )
);
Jim

Recommended Articles