how to find a exact word in a string?

24 次查看(过去 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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by