Counting the spesific word in text file
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
tinkyminky93
le 3 Juin 2022
Modifié(e) : Image Analyst
le 3 Juin 2022
Hello, I have a text file and I want to see how much 'Hi there!' word inside of it. How can I do it? Thank you.
2 commentaires
Walter Roberson
le 3 Juin 2022
What do you want to have happen if one of the occurrences is "PHi there!"? or "hi there!"?
Réponse acceptée
Image Analyst
le 3 Juin 2022
Modifié(e) : Image Analyst
le 3 Juin 2022
Did you try
fileChars = fileread(fileName);
locations = strfind(fileChars, 'Hi there!')
numLocations = numel(locations)
1 commentaire
Walter Roberson
le 3 Juin 2022
If you have "hi there" with lower case H, and you are searching for "Hi there!' with upper case H and with ! then the count should be 0.
Plus de réponses (2)
VINAYAK LUHA
le 3 Juin 2022
Modifié(e) : VINAYAK LUHA
le 3 Juin 2022
data = fileread("content.txt")
pattern="hi there!"
substr_freq =count(data,pattern)
%substr_freq has your answer
1 commentaire
Voir également
Catégories
En savoir plus sur Characters and Strings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!