cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
Get the free JMP Student Edition for qualified students and instructors at degree granting institutions.
Choose Language Hide Translation Bar
View Original Published Thread

Can I use Contains () with wildcard?

Neo
Neo
Level VI

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