Formatting HTTML

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Formatting HTTML

Post by lohill » Thu Jan 10, 2013 11:09 pm

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10330
Joined: Wed May 06, 2009 2:28 pm

Re: Formatting HTTML

Post by dunbarx » Thu Jan 10, 2013 11:21 pm

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

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: Formatting HTTML

Post by lohill » Thu Jan 10, 2013 11:41 pm

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

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Formatting HTTML

Post by Simon » Fri Jan 11, 2013 12:38 am

Hi Larry,
Look up isNumber in the dictionary.
and then use a
repeat for each char tChar in tVariable

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: Formatting HTTML

Post by lohill » Fri Jan 11, 2013 1:00 am

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

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: Formatting HTTML

Post by shaosean » Fri Jan 11, 2013 2:11 am

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

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: Formatting HTTML

Post by lohill » Fri Jan 11, 2013 3:05 am

shaosean,

Wow. It works, but it is going to take me some time to figure out what happened.

Larry

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: Formatting HTTML

Post by shaosean » Fri Jan 11, 2013 6:48 am

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

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Formatting HTTML

Post by Klaus » Fri Jan 11, 2013 12:50 pm

Hi Sean,
shaosean wrote:...just use the templateField for quick, in memory processing...
DAMN! 8)
I use MetaCard/Revolution/Livecode for over 12 years now and still learn something new almost every day! :D

Thanks a lot for this little gem!


Best

Klaus

Post Reply