is_str_in_str(c, str_match, is_case_sensitive)

Finds whether a string (or elements of a cell-array of strings) contains specified sub-strings.
121 descargas
Actualizado 20 jul 2015

Ver licencia

IS_STR_IN_STR finds whether a string (or elements of a cell-array of strings) contains at least one of a specified sub-string (or any of the elements of a cell-array of sub-strings).
L = IS_STR_IN_STR(X,PATTERN) returns a logical the same size as X indicating whether the pattern is in X.
X can be a string or cell-array of strings.
PATTERN can be a string*, cell-array of strings*, or a regular expression.
* Warning: REGEXP is used to find the occurences of strings so, for these, PATTERN should not include any regexp control characters (e.g. | or \ etc.).
L = IS_STR_IN_STR(X,PATTERN,TRUE) does the comparison as case-sensitive (otherwise the default is case-insensitive).
Example use:
cell_test = {'Black cat'; 'Cat and Dog'; 'white dog'; 'black dog'; 'blue bird'}
idx1 = is_str_in_str(cell_test, 'DOG');
idx2 = is_str_in_str(cell_test, 'dog', 1); %Case sensitive
idx3 = is_str_in_str(cell_test, {'black', 'blue'}); % Find cells with black OR blue
idx4 = is_str_in_str(cell_test, 'bla|blue'); % Find cells with black OR blue (specified via a regular expression).
[cell_test num2cell([idx1 idx2 idx3 idx4])]

Citar como

Roger Parkyn (2024). is_str_in_str(c, str_match, is_case_sensitive) (https://www.mathworks.com/matlabcentral/fileexchange/52175-is_str_in_str-c-str_match-is_case_sensitive), MATLAB Central File Exchange. Recuperado .

Compatibilidad con la versión de MATLAB
Se creó con R2010a
Compatible con cualquier versión
Compatibilidad con las plataformas
Windows macOS Linux
Categorías
Más información sobre Characters and Strings en Help Center y MATLAB Answers.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Versión Publicado Notas de la versión
1.1.0.0

Changed the help info at the top of the file and the Description for FileExchange.

1.0.0.0