is_str_in_str(c, str_match, is_case_sensitive)
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])]
引用
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. 取得済み .
MATLAB リリースの互換性
プラットフォームの互換性
Windows macOS Linuxカテゴリ
タグ
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!