Counting the spesific word in text file

2 次查看(过去 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
Walter Roberson 2022-6-3
What do you want to have happen if one of the occurrences is "PHi there!"? or "hi there!"?
tinkyminky93
tinkyminky93 2022-6-3
Phi there is not meaningful and it is impossible to found in my text file. But it is a good point.

请先登录,再进行评论。

采纳的回答

Image Analyst
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
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
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

tinkyminky93
tinkyminky93 2022-6-3
编辑:tinkyminky93 2022-6-3
you are right sir @Walter Roberson, I got the point.

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by