Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

search for specific word in text file in Matlab

Status
Not open for further replies.

Reem_Abdullah

Newbie level 4
Joined
Dec 12, 2011
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,319
I want to search for specific word in text file and return its position ...

this code read the text fine...

Code:
fid = fopen('jojo-1 .txt','r');

while 1

tline = fgetl(fid);

if ~ischar(tline)

break

end

end

but when I add this code
Code:
U = strfind(tline, 'Term');

it return [] although the string 'Term' exist in the file

can you please help me
 

Try this code on text.txt file which is attached. You get 13 and 1 which are the location of Term in 2nd and 3rd lines of text.txt

%%%%%%%%%%%%%%%%%%%%%%%
clc;
fid = fopen('text.txt','r');

tline = fgetl(fid)
while ischar(tline)
line_string = sprintf('%s',tline);
u = strfind(line_string, 'Term')
tline = fgetl(fid); %go to next line
end

fclose(fid);
%%%%%%%%%%%%%%%%%%%%%%%%%
 

Attachments

  • text.txt
    47 bytes · Views: 42

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top