How can I determine whether a string contains a substring?
741 views (last 30 days)
MathWorks Support Team on 16 Jun 2017
I have directory names that end in '0.0100'. I want to be able to skip certain directories by comparing the substring '0.0100' to the directory name. How can I do this?
MathWorks Support Team on 17 Nov 2022 at 5:00
Edited: MathWorks Support Team on 17 Nov 2022 at 9:16
You can use the 'contains' function to determine whether a string contains a given substring or not. Specifically, 'contains' returns true if the first argument contains the second argument and false otherwise. For example:
>> smallSubstring = '0.0100';
>> largeString1 = 'Item0.0100';
>> largeString2 = 'Item0.0101';
>> contains(largeString1, smallSubstring)
>> contains(largeString2, smallSubstring)
You may find more information about 'contains' at the following documentation page:
More Answers (2)
Royi Avital on 26 Aug 2018
Edited: MathWorks Support Team on 29 Nov 2022 at 3:56