Searching for a particular substring in a Text file
1 view (last 30 days)
Show older comments
Commented: Saeed Soltani on 27 May 2016
Hi everyone, I am searching for a particular part of my text file. I used textscan but the problem is I don’t know formatSpec well. My text file context looks like this:
I would like to get child names of SoftwareComponents, Actually the output must be:
It is my pleasure if someone can help. Thank you
Guillaume on 27 May 2016
Edited: Guillaume on 27 May 2016
It's not exactly clear what the actual format of your text file is. Are all entries just separated by one space?
Anyway, if the file consists just of a series of text strings, I wouldn't use textscan for that. I would simply read the whole file in one go, then use a regular expression to get the result:
filecontent = fileread('c:\somewhere\somefile.txt');
scchildren = regexp(filecontent, '(?<=/SoftwareComponents/)\w+', 'match')
Note that the above regular expression assumes that the name of a child consists only of characters from the set [A-Za-z_0-9].
More Answers (0)
Find more on Text Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!