txt file to string. trailing whitespace?
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Im trying to write a function that reads a txt file that is a paragraph of text line by line and returns a single string that is all those lines combined. This is part of that function:
while ~feof(ifstream)
str = strcat( str , fgetl(ifstream) , ' ' )
end
The lines in the txt file do not have trailing white space, but the returned string is supposed to... But adding the ' ' to the strcat() function seems to just be ignored by matlab.
Is there an easy way to fix this?
Thanks,
0 Kommentare
Antworten (1)
Walter Roberson
am 25 Mär. 2012
Please read the strcat documentation: it says explicitly the circumstances under which trailing spaces are discarded.
Use horzcat instead of strcat.
Your feof() code is also a bit wrong. Please read http://www.mathworks.com/matlabcentral/answers/22289-read-an-input-file-process-it-line-by-line
0 Kommentare
Siehe auch
Kategorien
Mehr zu Text Files finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!