How can I remove all spaces in a .txt file ?
古いコメントを表示
fid = fopen('test_hex.txt','r');
tline = fgetl(fid);
while ischar(tline)
disp(tline);
tline = fgetl(fid);
end
fclose(fid);
Here is my code to read txt file. I want to delete all spaces. How can I do it ? I have attached txt file
1 件のコメント
Brendan Hamm
2016 年 1 月 15 日
Inside your loop you can just write:
formatLine = regexprep(tline,' ','');
which will replace all spaces with the empty string. Now just decide how you want to store the data as this would overwrite the previous iteration everytime (maybe use a counter to store this outputto the kth row of a char array)
回答 (1 件)
If you really mean all as in "all"...
>> type burak.txt % made a file with your line twice...
08 0C F0 6D 86 EA 44 2D
08 0C F0 6D 86 EA 44 2D
>> fid=fopen('burak.txt','rt'); % open as text file to handle EOL
>> c=fread(fid,inf,'*char').'; % read into character array, transpose
c =
08 0C F0 6D 86 EA 44 2D
08 0C F0 6D 86 EA 44 2D
>> c(c==' ')=''; % remove blanks
c =
080CF06D86EA442D
080CF06D86EA442D
>> fid=fclose(fid);
Alternatively, use could still use strrep but for this purpose it's simpler to do the direct substitution.
c=strrep(c,' ','');
カテゴリ
ヘルプ センター および File Exchange で Large Files and Big Data についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!