Write text to web browser including carriage returns.
36 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Duncan Carlsmith
le 22 Nov 2024 à 1:50
Commenté : Duncan Carlsmith
le 23 Nov 2024 à 14:43
The following code displays a function saving the resulting text as a character array and attempts to display the result.
test=evalc('type readbmp');
str=strcat('text://<html>',test,'</html>')
web(str)
If I simply >>type readbmp, I get lines with carriage returns. If I display the character string via >>test, I get lines with carriage returns. But when I open the character string in the work space or use the web command, I get just one long unreadable character string.
I want to use these commands programmatically in a Live Script with long functions displayed outside a Live Script. How might I do this? Using a web browser seemed the simplist option rather than trying to create some gui window.
Réponse acceptée
Hitesh
le 22 Nov 2024 à 4:19
You need to use "strrep" function which will replace newline character (newline) in the captured text with HTML line break tags (<br>), preserving the line breaks in the web display. After that while concatenating the string use the <pre> tag which will preserves both spaces and line breaks. Please refer to the following code:
% Evaluate and capture the contents of 'readbmp'
test = evalc('type readbmp');
% Replace newline characters with HTML line breaks
test_html = strrep(test, newline, '<br>');
% Concatenate the HTML formatted string
str = strcat('text://<html><body><pre>', test_html, '</pre></body></html>');
% Open the formatted string in a web browser
web(str);
For more information regarding the "strrep" function, kindly refer to the below MATLAB documentation:
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Characters and Strings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!