Page 1 of 1
Formatting HTTML
Posted: Thu Jan 10, 2013 11:09 pm
by lohill
If I have a chunk of html text in a variable:
tVar="<td align=right>16.2512</td>"
I can say answer tVar and I get a nice looking 16.2512
What operation on tVar will convert tVar to a regular number?
Thanks Larry
Re: Formatting HTTML
Posted: Thu Jan 10, 2013 11:21 pm
by dunbarx
Hi.
Can you tell me what you mean by convert to a number?
When a field is set to the htmlText of your string, the value "16.2512" is represented according to the tags attached to the html string.
What do you want to see from that string that is not already there?
Craig Newman
Re: Formatting HTTML
Posted: Thu Jan 10, 2013 11:41 pm
by lohill
Hi Craid,
Can you tell me what you mean by convert to a number?
I guess I mean I want to get rid of all html markings so that I have a number in tVar, something that could be added to another number for example. My actual use is to put the number back into a place in the data grid.
Regards,
Larry
Re: Formatting HTTML
Posted: Fri Jan 11, 2013 12:38 am
by Simon
Hi Larry,
Look up isNumber in the dictionary.
and then use a
repeat for each char tChar in tVariable
Simon
Re: Formatting HTTML
Posted: Fri Jan 11, 2013 1:00 am
by lohill
Hello Simon,
Look up isNumber in the dictionary.
and then use a
repeat for each char tChar in tVariable
I had hoped for something better. If I have to do all that, my preference would be to use offset to get the '>', truncate there and then use offset to get the '<' and then take everything in between.
Regards,
Larry
Re: Formatting HTTML
Posted: Fri Jan 11, 2013 2:11 am
by shaosean
You guys do too much work to strip off the HTML tags, just use the templateField for quick, in memory processing..
Code: Select all
on mouseUp
local tVar
put "<td align=right>16.2512</td>" into tVar
set the htmlText of the templateField to tVar -- set the htmlText property
local tVarStripped
put the text of the templateField into tVarStripped -- grab the plain text that would be displayed
put tVarStripped
reset the templateField -- reset so creating a new field does not have your htmlText in it..
end mouseUp
Re: Formatting HTTML
Posted: Fri Jan 11, 2013 3:05 am
by lohill
shaosean,
Wow. It works, but it is going to take me some time to figure out what happened.
Larry
Re: Formatting HTTML
Posted: Fri Jan 11, 2013 6:48 am
by shaosean
Just make it a function that you can reuse..
Code: Select all
function htmlToText pHtml
set the htmlText of the templateField to pHtml
local tReturn
put the text of the templateField into tReturn
reset the templateField
return tReturn
end htmlToText
Re: Formatting HTTML
Posted: Fri Jan 11, 2013 12:50 pm
by Klaus
Hi Sean,
shaosean wrote:...just use the templateField for quick, in memory processing...
DAMN!
I use MetaCard/Revolution/Livecode for over 12 years now and still learn something new almost every day!
Thanks a lot for this little gem!
Best
Klaus