Code covered by the BSD License  

Highlights from
String comparison

String comparison

by

 

14 Aug 2013 (Updated )

The function searches for a string inside a given target and returns 1 for found or 0 for not found.

strcompare(target,searchterm)
function result = strcompare(target,searchterm)

% Function searches searchterm in your target string and returns 1 for found 
% or 0 for not found. The Target and searchterm can be either string or cell.

result = 0;
if iscell(target)==1&&iscell(searchterm)==1
result = ~cellfun('isempty', strfind(target, searchterm));

elseif iscell(target)==1&&ischar(searchterm)==1
result = ~cellfun('isempty', strfind(target, searchterm));

elseif ischar(target)==1&&iscell(searchterm)==1
searchterm = char(cellstr(searchterm));
result = any(strfind(target, searchterm));

elseif ischar(target)==1&&ischar(searchterm)==1
result = any(strfind(target, searchterm));
    
else
    error('Input is not a valid format, use string or cell')
end
    
end

Contact us