フィルターのクリア

compute the repetition of a string in a text file

3 ビュー (過去 30 日間)
Ferial Assmani
Ferial Assmani 2013 年 3 月 29 日
Dear all, how i compute the repetition of a special string in a file txt for example the A.txt file have the following lines;
AAA 1
1
2
AAA 2
BBB 1
i would have the number of the AAA repetition which is 2
Thanks

採用された回答

Cedric
Cedric 2013 年 3 月 29 日
編集済み: Cedric 2013 年 3 月 29 日
Your best option for pattern matching is usually regular expressions (regexp).
In this particular situation where the pattern is simple, you can go for a simpler solutions though, as follows:
>> buffer = fileread('A.txt') ;
>> n = numel(strfind(buffer, 'AAA')) ;
Let me know if the pattern is indeed more complicated than a simple string, or if you must differentiate 'AAA' from 'AAAA' for example or avoid matching 'BAAABBB'.
  1 件のコメント
Ferial Assmani
Ferial Assmani 2013 年 3 月 29 日
Thanks, it work 10/10

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by