Dec 12, 2011 #1 R 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
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
Dec 13, 2011 #2 T tariq786 Advanced Member level 2 Joined Feb 24, 2004 Messages 562 Helped 67 Reputation 134 Reaction score 54 Trophy points 1,308 Location USA Activity points 3,049 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: 44
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); %%%%%%%%%%%%%%%%%%%%%%%%%
Dec 15, 2011 #3 R 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 thanks i decided to go in another direction