strcmp for a part of the word

28 vues (au cours des 30 derniers jours)
alpedhuez
alpedhuez le 2 Juil 2020
Modifié(e) : alpedhuez le 5 Juil 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 commentaires
Stephen23
Stephen23 le 4 Juil 2020
Modifié(e) : Stephen23 le 4 Juil 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 le 4 Juil 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.

Connectez-vous pour commenter.

Réponse acceptée

madhan ravi
madhan ravi le 2 Juil 2020
Use contains()

Plus de réponses (0)

Catégories

En savoir plus sur Desktop dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by