String Escape

returns a string with special characters "escaped"
252 Downloads
Aktualisiert 16. Jul 2013

Lizenz anzeigen

function result = stresc(string)
returns a string with special characters "escaped"

i.e., the string "Randy's wonton\n % delicious!" becomes
"Randy''s wonton \\n %% delicious!".

Thus, the resulting string is suitable to be printed out and
interpreted by MATLAB. This function is especially useful if you are
writing code intended to produce code. Interpreted strings can be
freely placed into your code without worry of strings breaking code.

The following conversions are made:
% becomes %%
\ becomes \\
' becomes ''

Example Usage:
myString = inputdlg('Please enter a string you want printed',...
'Test StrEsc');
fprintf('%s\n', stresc(myString{1})); % original string, escaped
fprintf('fprintf(''%s'');\n', myString{1}); % won't work for all strings
fprintf('fprintf(''%s'');\n', stresc(myString{1}));

Zitieren als

Alexander Saites (2026). String Escape (https://de.mathworks.com/matlabcentral/fileexchange/42652-string-escape), MATLAB Central File Exchange. Abgerufen.

Kompatibilität der MATLAB-Version
Erstellt mit R2013a
Kompatibel mit allen Versionen
Plattform-Kompatibilität
Windows macOS Linux
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und MATLAB Answers
Version Veröffentlicht Versionshinweise
1.0.0.0