how to find a exact word in a string?

조회 수: 23 (최근 30일)
gmltn1212
gmltn1212 2020년 7월 5일
댓글: Chandan 2023년 10월 11일
Hi I am trying to return the value that matches with a given word in a string...
str = 'talk talking people talk talking talk'
if this is my string and I am trying to return how many times 'talk' shows up in the string, what should I do?
this is my code so far but it also returns 'talking'... is there any other way to fix this?
find = strfind(str, 'talk')

답변 (1개)

Walter Roberson
Walter Roberson 2020년 7월 5일
length(regexp(str, '\<talk\>'))
  댓글 수: 4
Walter Roberson
Walter Roberson 2020년 7월 5일
Madhan is correct, ['\<' word1 '\>'] as the pattern
Chandan
Chandan 2023년 10월 11일
Thanks you, It works perfect

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by