strcmp for a part of the word

25 views (last 30 days)
alpedhuez
alpedhuez on 2 Jul 2020
Edited: alpedhuez on 5 Jul 2020
I understand strcmp(A,B) compares strings A and B. But suppose I have
'Toyota 2020', 'Toyota 2019',...
and I want to check whether these strings contain the word 'Toyota" or not. Is it possible?
  5 Comments
Stephen23
Stephen23 on 4 Jul 2020
Edited: Stephen23 on 4 Jul 2020
"Yes but in this case compare only a part of a string. "
strncmp works when I try it:
>> strncmp('Toyota',{'Toyota 2020','Toyota 2019'},6)
ans = 1 1
alpedhuez
alpedhuez on 4 Jul 2020
Yes in this toy example. But the real example is not that clean: it has '2017 Toyota'. Thus this approach, although works in the toy example, does not generalize.

Sign in to comment.

Accepted Answer

madhan ravi
madhan ravi on 2 Jul 2020
Use contains()

More Answers (0)

Categories

Find more on Desktop in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!