How can i remove all spaces from all lines in a text file?

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

Risposte (2)

the cyclist
the cyclist il 24 Mag 2016
Modificato: the cyclist il 24 Mag 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.
Stephen23
Stephen23 il 24 Mag 2016
Modificato: Stephen23 il 24 Mag 2016
Here is a fast solution in just three lines:
>> fid = fopen('text_out.txt','wt');
>> fprintf(fid,'%s',strrep(fileread('text_in.txt'),' ',''))
>> fclose(fid);

Categorie

Richiesto:

il 24 Mag 2016

Commentato:

il 25 Mag 2016

Community Treasure Hunt

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

Start Hunting!

Translated by