Finding the unknown text 'x' chars to the right of the known

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
Andycal
Posts: 144
Joined: Mon Apr 10, 2006 3:04 pm

Finding the unknown text 'x' chars to the right of the known

Post by Andycal » Fri Dec 04, 2009 3:02 pm

I'm trying to get the share price of certain stocks out of Yahoo. When you do a search (which is easy), I'm then loading it into a text box and filtering the web page to just get the line with the share details in, all good so far.

Here's an extract:

Code: Select all

<span style="color:#333333;">Share Price:</span> 62.35</td><td><span style="color:#333333;">Bid:</span>
Now, I want to extract the share price, so I need to get the value 8 characters to the right of the words 'Share Price'. Anyone know how to do that?

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

Re: Finding the unknown text 'x' chars to the right of the known

Post by dunbarx » Fri Dec 04, 2009 3:38 pm

Try this:

Code: Select all

on mouseUp
   get offset("share price",yourRawdata)
   put char (it + 20) to (it + 28) of yourRawdata into temp --should be enough room to grab the price
   
   repeat for each char tChar in temp --extract just numbers and dec. point
      if tChar is in "0123456789." then put tChar after SharePrice
   end repeat
   answer sharePrice
end mouseUp

Andycal
Posts: 144
Joined: Mon Apr 10, 2006 3:04 pm

Re: Finding the unknown text 'x' chars to the right of the known

Post by Andycal » Fri Dec 04, 2009 3:48 pm

Absolutely perfect!! Thanks bud, I definately owe you a pint for that bit of genius!

Post Reply