Left Justifying a String obtained from the formattedDisplayText() function

about extracting header info from a CSv file and /Chris LaPiere kindly showed a way.
I often want to display info in a textarea rather than go and look in the command window and used this.
str = formattedDisplayText(header text,'SuppressMarkup',true,'LineSpacing','compact');
I then set the textarea text to this.
However, it doesn't appear left justified. I did also try this but it also had no effect
str=strjust(str,'left');
Is it even possible to get it left justified (in the textarea) - the header text begins at "Format "1.0B"
it does also appear like this in the command window
str =
"Format: '1.0B'
MemoryLength: 1000000
IntpDistance: 0
TriggerAddress: -51001
TriggerLevel: 2.3600
Source: 'CH1'
VerticalUnits: 'V'
VerticalUnitsDiv: 0
VerticalUnitsExtendDiv: 16

 採用された回答

Stephen23
Stephen23 2025 年 2 月 13 日
編集済み: Stephen23 2025 年 2 月 13 日
You would have to delete all leading space that occurs after any newline characters, e.g.:
str = regexprep(str,'^[ \t]+','', 'lineanchors')
or
spl = strtrim(strsplit(str,newline))
or similar.
Note that STRJUST does not justify each line (i.e. separated with newlines), it justifies the entire text as one (i.e. it only considers the leading/trailing whitespace of the entire text, not each line within the text).

2 件のコメント

Jason
Jason 2025 年 2 月 13 日
編集済み: Jason 2025 年 2 月 13 日
thankyou,
this worked a dream
str = regexprep(str,'^[ \t]+','', 'lineanchors')
But this one didn't
spl = strtrim(strsplit(str,newline))
Stephen23
Stephen23 2025 年 2 月 13 日
@Voss: thank you, fixed now!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

製品

リリース

R2023b

質問済み:

2025 年 2 月 13 日

コメント済み:

2025 年 2 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by