String Escape
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
Plattform-Kompatibilität
Windows macOS LinuxKategorien
Tags
Live Editor erkunden
Erstellen Sie Skripte mit Code, Ausgabe und formatiertem Text in einem einzigen ausführbaren Dokument.
| Version | Veröffentlicht | Versionshinweise | |
|---|---|---|---|
| 1.0.0.0 |
