Searching multiple Strings in file
1 次查看(过去 30 天)
显示 更早的评论
Hi,
The typical file format is as follows:
channelCfg 15 3 0
adcCfg 2 1
adcbufCfg -1 0 0 1 0
The text file is read. The keywords are adcCfg and adcbufCfg. Searching for the keywords only integers in that line have to be stored in a vector. I tried to get something to work with regexp and strfind but got no satisfying results.
Regards
0 个评论
采纳的回答
Guillaume
2018-8-7
but got no satisfying results
And what is a statisfying result?
Is this what you're after?
filecontent = fileread('c:\somewhere\somefile.txt');
adclines = regexp(filecontent, '(?<=adc(buf)?Cfg).*', 'match', 'dotexceptnewline');
adcnumbers = cellfun(@str2double, regexp(adclines, '[+-]?\d+', 'match'), 'UniformOutput', false);
celldisp(adcnumbers)
3 个评论
Guillaume
2018-8-7
not intuitive
Like any language, you have to learn it. It is very self-consistent and once you know it very intuitive.
Alternatively multiple expressions are added with or: '|'.
I'm not sure why you are mentioning this.
Is your question answered then?
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!