strcmp for a part of the word

27 ビュー (過去 30 日間)
alpedhuez
alpedhuez 2020 年 7 月 2 日
編集済み: alpedhuez 2020 年 7 月 5 日
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 件のコメント
Stephen23
Stephen23 2020 年 7 月 4 日
編集済み: Stephen23 2020 年 7 月 4 日
"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 2020 年 7 月 4 日
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.

サインインしてコメントする。

採用された回答

madhan ravi
madhan ravi 2020 年 7 月 2 日
Use contains()

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDesktop についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by