find specific text in a text file

조회 수: 2 (최근 30일)
amin
amin 2020년 2월 13일
댓글: amin 2020년 2월 17일
Hi
In the text file below, I want to obtain everything between "|[" and "]|".
system
component1 |[ b,a,d, w,e,r ]| component2
endsystem
so the output is : b,a,d, w,e,r
Thanks in advance.

채택된 답변

Srivardhan Gadila
Srivardhan Gadila 2020년 2월 16일
Please refer to the functions fileread & regexp.
Let's assume that the following content
"system
component1 |[ b,a,d, w,e,r ]| component2
endsystem"
is in a text file named textFile.txt then the following code might help you:
textChar = fileread("textFile.txt");
startIndex = regexp(textChar,'|[');
endIndex = regexp(textChar,']|');
requiredOutput = textChar(startIndex+1:endIndex-2)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by