Effacer les filtres
Effacer les filtres

how to find a exact word in a string?

12 vues (au cours des 30 derniers jours)
gmltn1212
gmltn1212 le 5 Juil 2020
Commenté : Chandan le 11 Oct 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')

Réponses (1)

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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by