Counting the spesific word in text file

4 visualizaciones (últimos 30 días)
tinkyminky93
tinkyminky93 el 3 de Jun. de 2022
Editada: Image Analyst el 3 de Jun. de 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 comentarios
Walter Roberson
Walter Roberson el 3 de Jun. de 2022
What do you want to have happen if one of the occurrences is "PHi there!"? or "hi there!"?
tinkyminky93
tinkyminky93 el 3 de Jun. de 2022
Phi there is not meaningful and it is impossible to found in my text file. But it is a good point.

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 3 de Jun. de 2022
Editada: Image Analyst el 3 de Jun. de 2022
Did you try
fileChars = fileread(fileName);
locations = strfind(fileChars, 'Hi there!')
numLocations = numel(locations)
  1 comentario
Walter Roberson
Walter Roberson el 3 de Jun. de 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.

Iniciar sesión para comentar.

Más respuestas (2)

VINAYAK LUHA
VINAYAK LUHA el 3 de Jun. de 2022
Editada: VINAYAK LUHA el 3 de Jun. de 2022
data = fileread("content.txt")
pattern="hi there!"
substr_freq =count(data,pattern)
%substr_freq has your answer
  1 comentario
tinkyminky93
tinkyminky93 el 3 de Jun. de 2022
Editada: tinkyminky93 el 3 de Jun. de 2022
Search term must be a text or pattern array, error using count

Iniciar sesión para comentar.


tinkyminky93
tinkyminky93 el 3 de Jun. de 2022
Editada: tinkyminky93 el 3 de Jun. de 2022
you are right sir @Walter Roberson, I got the point.

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by