how to find a exact word in a string?

19 visualizaciones (últimos 30 días)
gmltn1212
gmltn1212 el 5 de Jul. de 2020
Comentada: Chandan el 11 de Oct. de 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')

Respuestas (1)

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

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by