cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
ErraticAttack
Level VI

TextBox Markup Get Plain Text

Does anyone know of a way to get the plain-text of a TextBox that has markup text applied?  For instance, in the below example I'd like to get the text "This is bold text. This is italic text. This is underlined text. This is bold, italic, underlined text." from the box (without the markup directives).

 

I have a system that creates logs at the bottom of some apps that supports markup (for bold and red font mostly), but I'd like to be able to save the log to a file occasionally and not have it have the markup directives.

 

Thanks!

 

Names Default To Here( 1 );
win = New Window( "Example", fontobj = text = Text Box( "Example Text" ) );
text << setText(
	"This is <b>bold</b> text. This is <i>italic</i> text. This is <u>underlined</u> text. This is <b><i><u>bold, italic, underlined</u></i></b> text."
);
text << markup;
Jordan
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: TextBox Markup Get Plain Text

Only some sort of Regex comes to my mind, but the pattern might get annoying to build

Names Default To Here( 1 );
win = New Window( "Example", fontobj = text = Text Box( "Example Text" ) );
text << setText(
	"This is <b>bold</b> text. This is <i>italic</i> text. This is <u>underlined</u> text. 
This is <b><i><u>bold, italic, underlined</u></i></b> text.
Text using a <font face='Vivaldi'>different</font> font face.
Text using a <font size='16'>different</font> font size.
This is <font color='Blue'>blue</font> text. This is a <background color='yellow'>yellow</background> background. This is <font color='#0000ff'><background color='0xffff00'>blue text on a yellow background</background></font>."
);
text << markup;
Regex(text << get text, "(</?.*?>)", "", GLOBALREPLACE);
-Jarmo

View solution in original post

2 REPLIES 2
jthi
Super User

Re: TextBox Markup Get Plain Text

Only some sort of Regex comes to my mind, but the pattern might get annoying to build

Names Default To Here( 1 );
win = New Window( "Example", fontobj = text = Text Box( "Example Text" ) );
text << setText(
	"This is <b>bold</b> text. This is <i>italic</i> text. This is <u>underlined</u> text. 
This is <b><i><u>bold, italic, underlined</u></i></b> text.
Text using a <font face='Vivaldi'>different</font> font face.
Text using a <font size='16'>different</font> font size.
This is <font color='Blue'>blue</font> text. This is a <background color='yellow'>yellow</background> background. This is <font color='#0000ff'><background color='0xffff00'>blue text on a yellow background</background></font>."
);
text << markup;
Regex(text << get text, "(</?.*?>)", "", GLOBALREPLACE);
-Jarmo
ErraticAttack
Level VI

Re: TextBox Markup Get Plain Text

Awesome idea!  It hadn't occurred to me to use regex, but that is pretty slick.

Jordan