Write text to web browser including carriage returns.

조회 수: 34 (최근 30일)
Duncan Carlsmith
Duncan Carlsmith 2024년 11월 22일 1:50
댓글: Duncan Carlsmith 2024년 11월 23일 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.

채택된 답변

Hitesh
Hitesh 2024년 11월 22일 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개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품


릴리스

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by