containstr

版本 1.2.1 (7.9 KB) 作者: wfH
Search strings that match multiple patterns with a single line of code.
55.0 次下载
更新时间 2021/9/7

查看许可证

`containstr` returns TRUE if PATTERNs is found in text S.
`startswith` returns TRUE if any element of PATTERNs at the start of text S.
`endswith` returns TRUE if any element of PATTERNs at the end of text S.
Usage:
containstr(S, PATTERN)
startswith(S, PATTERN)
endswith(S, PATTERN)
--------------------------------------------------------------------------
Sometimes, I need to search strings that match multiple patterns.
The use of `strfind` (`regexp`) combing with for-loop (`cellfun`) makes the script look long and messy.
In newer version (R2016b), it is easy to do in a single line of code.
Just call the built-in functions `contains`, `startsWith`, or `endsWith`.
So, I created these functions for users with older version to search pattern in text.
These functions follow the same behaviour as Matlab's built-in.
Besides, my functions can treat search pattern as regular expression as needed.
No more for-loop is needed

引用格式

wfH (2024). containstr (https://www.mathworks.com/matlabcentral/fileexchange/70334-containstr), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2017a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.2.1

fix bugs

1.2.0

new functions `startswith`, `endswith`;
bug fix;
add output argument `AGONIST`;

1.1.2

fix bug

1.1.1

rewrite a concise version, and add 'regexp' engine

1.0.1

clear description

1.0.0