MATLAB: How to find the location of the first string matching the searching criteria

MATLABtext querry

My goal is to find the column number of the variables stored in my Excel file. Below is my code. Now B stores the column headers. For example B{1,1} is the first variable name, B{1,2} is the second header name, and so on.
% --- load the file ---
File1 = ['workingFolder/abc.xlsx'];
[A, B C] = xlsread (File1); % B stores the column headers of my Excel file
How do I write a program so that B{N,2} (N is the number of the column I'm hoping to get) would meet the below searching criteria :
a) It has to contain both string1 and string2.
b) N is the first column meeting that criteria.
For example, a column header with the name of 'ABCDEFG_GKLM' would meet the search criteria of having both 'BCD', and 'KL' in the term.
Many thanks!

Best Answer

Assuming you can get a cell array B of character vectors containing the headers, and the strings you want to match assigned to string1 and string2 then this should work:
% get vector of logicals whose elements are set to true wherever both matching criteria are met
% use 'IgnoreCase',true to make it insensitive to the case of the headers
isMatch = contains(B,string1,'IgnoreCase',true) & contains(B,string2,'IgnoreCase',true)
% now find the index of the first match, this will be the column number you are looking for
N = find(isMatch,1,'first')