how to find a exact word in a string?

22 Ansichten (letzte 30 Tage)
gmltn1212
gmltn1212 am 5 Jul. 2020
Kommentiert: Chandan am 11 Okt. 2023
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')

Antworten (1)

Walter Roberson
Walter Roberson am 5 Jul. 2020
length(regexp(str, '\<talk\>'))
  4 Kommentare
Walter Roberson
Walter Roberson am 5 Jul. 2020
Madhan is correct, ['\<' word1 '\>'] as the pattern
Chandan
Chandan am 11 Okt. 2023
Thanks you, It works perfect

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by