You are now following this Submission
- You will see updates in your followed content feed
- You may receive emails, depending on your communication preferences
`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
Cite As
wfH (2026). containstr (https://www.mathworks.com/matlabcentral/fileexchange/70334-containstr), MATLAB Central File Exchange. Retrieved .
General Information
- Version 1.2.1 (7.89 KB)
MATLAB Release Compatibility
- Compatible with any release
Platform Compatibility
- Windows
- macOS
- Linux
