Counting the spesific word in text file
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2022-6-3
What do you want to have happen if one of the occurrences is "PHi there!"? or "hi there!"?
采纳的回答
Image Analyst
2022-6-3
编辑:Image Analyst
2022-6-3
Did you try
fileChars = fileread(fileName);
locations = strfind(fileChars, 'Hi there!')
numLocations = numel(locations)
1 个评论
Walter Roberson
2022-6-3
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.
更多回答(2 个)
VINAYAK LUHA
2022-6-3
编辑:VINAYAK LUHA
2022-6-3
data = fileread("content.txt")
pattern="hi there!"
substr_freq =count(data,pattern)
%substr_freq has your answer
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!