Counting the spesific word in text file

7 ビュー (過去 30 日間)
tinkyminky93
tinkyminky93 2022 年 6 月 3 日
編集済み: Image Analyst 2022 年 6 月 3 日
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
  1 件のコメント
tinkyminky93
tinkyminky93 2022 年 6 月 3 日
編集済み: tinkyminky93 2022 年 6 月 3 日
Search term must be a text or pattern array, error using count

サインインしてコメントする。


tinkyminky93
tinkyminky93 2022 年 6 月 3 日
編集済み: tinkyminky93 2022 年 6 月 3 日
you are right sir @Walter Roberson, I got the point.

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by