append (not strcat) to combine strings with whitespace (\n)
이전 댓글 표시
I have a text box (text edit field, shoud it be a label box?)
I want to add lines of text to it without loosing the old text.
app.DebugField.Value = append(app.DebugField.Value, "rew LB\n");
but the newlines are showing up as text \n
Start Trials at 22:26:09 >> rew LB\n
I guess I have to sprintf() the string first but why can't \n be properly interpreted by string handling functions?
댓글 수: 3
Image Analyst
2024년 8월 1일
Maybe try to append a linefeed?
app.DebugField.Value = append(app.DebugField.Value, ['rew LB', char(10)]);
Gavin
2024년 8월 1일
"I guess I have to sprintf() the string first but why can't \n be properly interpreted by string handling functions?"
Only the functions which are documented to interpret such special characters (e.g. SPRINTF, FPRINTF, COMPOSE, etc.) will interpret such escaped sequences. Text operations such as concatenation do not interpret anything.
"... even sprintf() to magically turn \n into hex13 hex 10 isn't working!"
Note that carriage return is actually decimal 13 (hex: D) and line feed is decimal 10 (hex: A).
If you want a carriage return followed by a line feed then you can specify this:
txt = sprintf('%s\r\n','hello','world')
double(txt) % check that char(13) and char(10) have been created
Voss advised that an EDIT FIELD is for a single line of text. Use a TEXT AREA if you want to display multiple lines:
채택된 답변
추가 답변 (2개)
Voss
2024년 8월 1일
1 개 추천
From here:
"If you want to allow multiple lines of text, use a text area component instead of an edit field."
Walter Roberson
2024년 8월 6일
app.DebugField.Value = append(app.DebugField.Value, "rew LB" + newline);
카테고리
도움말 센터 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!