Counting the spesific word in text file
조회 수: 8 (최근 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에서 Cell Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!