Counting the spesific word in text file
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
tinkyminky93
il 3 Giu 2022
Modificato: Image Analyst
il 3 Giu 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 Commenti
Walter Roberson
il 3 Giu 2022
What do you want to have happen if one of the occurrences is "PHi there!"? or "hi there!"?
Risposta accettata
Image Analyst
il 3 Giu 2022
Modificato: Image Analyst
il 3 Giu 2022
Did you try
fileChars = fileread(fileName);
locations = strfind(fileChars, 'Hi there!')
numLocations = numel(locations)
1 Commento
Walter Roberson
il 3 Giu 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.
Più risposte (2)
VINAYAK LUHA
il 3 Giu 2022
Modificato: VINAYAK LUHA
il 3 Giu 2022
data = fileread("content.txt")
pattern="hi there!"
substr_freq =count(data,pattern)
%substr_freq has your answer
Vedere anche
Categorie
Scopri di più su Characters and Strings in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!