Write text to web browser including carriage returns.
34 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Duncan Carlsmith
el 22 de Nov. de 2024 a las 1:50
Comentada: Duncan Carlsmith
el 23 de Nov. de 2024 a las 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.
Respuesta aceptada
Hitesh
el 22 de Nov. de 2024 a las 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!