MATLAB Answers

strcmp for a part of the word

4 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

Show 2 older comments
alpedhuez
alpedhuez on 3 Jul 2020
Yes but in this case compare only a part of a string.
Stephen Cobeldick
Stephen Cobeldick 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()

  0 Comments

Sign in to comment.

More Answers (0)

Tags


Translated by