- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Case Insensitive searches
Hi,
Most JMP is case insensitive except when it comes to text values.
Since text data is often messy and case is one way it shows up, is there a way to do case insensitive versions of Contains?
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Case Insensitive searches
regex is case sensitive by default, PatMatch is insensitive by default.
regex("The Quick Brown Fox", "quick", "\0", IGNORECASE); "Quick" regex("The Quick Brown Fox", "quick", "\0"); returns missing rc = PatMatch("The Quick Brown Fox", patPos()>>where + "quick">>what); show(rc,where,what); rc = 1; where = 4; what = "Quick"; PatMatch("The Quick Brown Fox", patPos()>>where + "quick">>what, NULL, MATCHCASE); returns 0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Case Insensitive searches
If you want to specifically use Contains(), you can use Lowercase() or Uppercase() to perform case-insensitive searches:
str1 = "Hello";
str2 = "ELL";
Contains( Lowercase(str1), Lowercase(str2) );
Contains( Lowercase(str1), "ell" );
Contains( Lowercase(str1), Lowercase("Ell") );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Case Insensitive searches
regex is case sensitive by default, PatMatch is insensitive by default.
regex("The Quick Brown Fox", "quick", "\0", IGNORECASE); "Quick" regex("The Quick Brown Fox", "quick", "\0"); returns missing rc = PatMatch("The Quick Brown Fox", patPos()>>where + "quick">>what); show(rc,where,what); rc = 1; where = 4; what = "Quick"; PatMatch("The Quick Brown Fox", patPos()>>where + "quick">>what, NULL, MATCHCASE); returns 0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Case Insensitive searches
If you want to specifically use Contains(), you can use Lowercase() or Uppercase() to perform case-insensitive searches:
str1 = "Hello";
str2 = "ELL";
Contains( Lowercase(str1), Lowercase(str2) );
Contains( Lowercase(str1), "ell" );
Contains( Lowercase(str1), Lowercase("Ell") );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Case Insensitive searches
this was helpful to me and I think it should be mentioned in the Help for the Contains function, which does not even mention that the function is case-sensitive.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Case Insensitive searches
more information on case and regex: Back Reference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Case Insensitive searches
If you're trying to find a matching item in a list of strings (say column titles) and you want to match JMP's default of ignoring case / spaces, you can use the As Name function, see below
Names Default to Here( 1 );
list = {"Height", "Weight", "CamelCase", "__Dunder_Mifflin__" };
Show( Contains( list, "camel case" ) ); // 0
named list = {};
For( i = 1, i <= N Items( list ), i++,
named list[i] = As Name( list[i] )
);
Show( Contains( named list, As Name( "camel case" ) ) ); // 3