フィルターのクリア

Reading only those lines starting with a specific string

19 ビュー (過去 30 日間)
Nachiket Patki
Nachiket Patki 2018 年 4 月 29 日
回答済み: Ameer Hamza 2018 年 4 月 29 日
Hello, I have a text file. Now I want to read only those line which start with particular strings only. For example, I have sentences in text file as...
1_xyz_sdf_rtuy_errt
2_dsgs_sdfs_sfs_ewtw
3_sd_sddgs_ewetertert
4_....
etc
(The numbers from starting of each line will go on increasing) where you can see each line starts with a string 1 or 2 or 3 etc, so I have to check whether particular line starts with 1 if YES the find 'xyz' string from the line. similarily if line starts with 2 then find another 'xyz' string so on and so forth... Can anyone please help me?
Thank you

回答 (1 件)

Ameer Hamza
Ameer Hamza 2018 年 4 月 29 日
It might be a better solution to read the entire file into memory using textscan() and then search for a particular line or string.
If you just want to search the file once or still want to incrementally search the file, then just use fgetl(), to read lines one by one from the text file and search until you reach required line.

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by