I am trying to read in a text file where each row contains a string. Some rows contain the character combination '\n' and '\r', and then all rows end with a CR and LF marker (I opened the file in Notepad++ to see this). For example:
First NameBirthdateAverage\nLengthAvoid\rWater
…and so on.
The issue is that when I use textscan and set either '\n' or '\r' as the delimiter, MATLAB parses the incoming file at every '\n' or '\r' and CR or LF, where I need to only have actual carriage returns and line feeds break the line. Is there some sort of identifier I can use to differentiate a CR/LF from '\n' and '\r'?
fid=fopen('text.txt', 'r+');full=textscan(fid, '%s', 'Delimiter', '\n') % I tried with '\r' as delimiter as well, and the result is the same
printFile=fopen('results.txt', 'at');for i=1:length(full{1}) str=full{1}{i}; str=strrep(str, '\n', '$'); % I need to input a '$' as a manual delimiter in place of actual CR and LF.
% However this will replace both '\n' *and* CR/LF with '$'.
fprintf(printFile, '%s$', str); endfclose all;
Best Answer