Choose Language Hide Translation Bar
ENTHU
Community Trekker

Case Insensitive searches using contains

I am using the following piece of code to check if the list cn contains "col_name" and if yes rename it as Target.The problem is col_name can be all upper case or lowercase and there is no way for me to control that.How do I make sure that the code gets executed irrespective of the case?

 

If( Contains( cn ,Lowercase("col_name") ),  


:"col_name" << Set name("Target");

);

 

Thanks

0 Kudos
3 REPLIES 3
gianpaolo
Community Trekker

Re: Case Insensitive searches using contains

hello,

i think you can apply "substitute" ... follow the below example

  

Names Default To Here( 1 );

lst = {"a", "lowercase", "c"};

Substitute( lst, "lowercase", "Target" );

 

ciao

Gianpaolo

Gianpaolo Polsinelli
0 Kudos
txnelson
Super User

Re: Case Insensitive searches using contains

What is "cn"? A List, a String, an Associative Array???
Is "col_name" supposed to be referring to the name of a column?

Please provide more specifics

Jim
0 Kudos
pmroz
Super User

Re: Case Insensitive searches using contains

There's no need to use lowercase() on col_name because it's already in lowercase.  This code will do what you want:

dt = New Table( "Untitled 2", Add Rows( 1 ),
	New Column( "COL_Name", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1] ) ),
	New Column( "Column 2", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2] ) ),
	New Column( "Column 3", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [3] ) )
);
cn_list = dt << get column names(string);
for (i = 1, i <= nitems(cn_list), i++,
	cn_list[i] = lowercase(cn_list[i]);
);

If( Contains( cn_list, "col_name" ),
	:"col_name" << Set name("Target");
);
0 Kudos