Problem with saving file with built in new line
Info
This question is closed. Reopen it to edit or answer.
Show older comments
To get the username from the system, I'm using the follow syntax:
if ispc()
[~,username] = system('echo %username%'); %On Windows
else
[~,username] = system('echo $USER'); %On MAC
end
This will return the username as a string. But there will be a newline character at the end of the username, how can I get the username without the newline character at the end? I'm also using the built-in date() function.
function saveTable(A,B,C,D)
mat1 = [A, B, C];
if ispc
[~,username] = system('echo %username%'); %On Windows
else
[~,username] = system('echo $USER'); %On Mac
end
str1 = fprintf('%s',D);
str2 = fprintf('%s',username);
str3 = date;
filename1=fprintf('%s_%s_%s',str1,str2,str3,'s');
save filename1.dat mat1 -ascii
end
Answers (1)
dpb
on 1 Mar 2014
I generally just do the expedient for such stuff --
username=username(username>=' ');
You can be more elegant (for some definition of "elegant" :) ) with regexp or the like but the above deals with whichever is the actual \n sequence, one or two characters.
1 Comment
Joseph
on 1 Mar 2014
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!