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 CenterFile Exchange에서 Desktop에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by