How can i remove all spaces from all lines in a text file?
13 views (last 30 days)
Show older comments
In a text file i want to remove all spaces from all the lines to create a file with the same lines , but without the spaces
0 Comments
Answers (2)
the cyclist
on 24 May 2016
Edited: the cyclist
on 24 May 2016
Here is one way:
fid_in = fopen('text_in.txt');
fid_out = fopen('text_out.txt','w');
text_in = fgetl(fid_in);
while ischar(text_in)
text_out = [regexprep(text_in,' ','')];
fprintf(fid_out,'%s\n',text_out);
disp(text_in)
disp(text_out)
text_in = fgetl(fid_in);
end
fclose(fid_in);
fclose(fid_out);
I tested it on the attached file.
0 Comments
See Also
Categories
Find more on MATLAB Report Generator 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!