This is a calculation, not a script:
Let ( [ RawT = YourTextField ;
start = position ( RawT ; "price\" content=\"$" ; 1; 1 ) ;
end = position (RawT ; "\"" ; start ; 3 )
GetAsNumber ( Middle ( RawT ; start ; end - start ) )
it works! Thanks so much.
I've been looking everywhere how this text stripping through Let in combo with start/end works. Would you explain a bit what you've done here?
I have 3 other ones I need, but would like to also know in the future how to isolate and grab other data from html files:
itemprop="ratingCount" content="12000" [want to paste the found number 12000 in a ratingcount field]
"itemprop="ratingValue" content="4.1" [want to paste the found number 4.1 in a ratingvalue field]
Android:</dt><dd>2.1 and up</dd><dt> [want to paste the found text "2.1 and up" in a Androidversion field]
I suggest you look up each of these functions in help to learn more.
Let allows you to define temporary values to be used later in a calculation. It's a useful way to break up a complex calcualtion into smaller, easier to manage pieces and can also reduce the amount of typing needed by subsituting a simpler variable for a long table::fieldname.
Position returns a number identifying the position of the specified text in your field. The parameters after control the starting point and the occurrence number needed. Thus position (RawT ; "\"" ; start ; 3 ) starts searching through the text in RawT starting at the position in start to find the 3rd occurrence of a double quote located to the right of that starting point.
the backslash is an escape character that enables you to insert a quotation mark inside a screen so that Filemaker does not interpret it as the end of a string expression.
Thus, Filemaker evaluates \" as just the double quote character.
Thanks again for your excellent explanation!
I now ran into a variation of the same challenge where the returns were text. I used GetAsText instead. I don't seem to be able to control the starting point in the text. With the script below I got as return: "Requirements: </span>Compatible with iPhone 3GS". It should have been "Compatible with iPhone 3GS".
The script was applied to raw html text that included this text:
Requirements: </span>Compatible with iPhone 3GS</p>
This was my script:
Let( [ RawT = MyTextField ; start = Position ( RawT ; "Requirements: </span>" ; 1; 1 ) ; end = Position (RawT ; "<" ; start ; 2 ) ]; GetAsText ( Middle ( RawT ; start ; end - start ) ) )
Any suggestions of how to control the starting point? (I experimented with the "1" and "1" in the start phrase, but that didn't seem to hel)
Getastext has no effect in this calculation. (This is not a script, BTW. It's a calculation.)
Start is calculating the position of the "R" in "Requirements".
End is calculating the postion of the second "<" to be found to the right of start, which should be the position of < in </p>.
Middle then returns the text shown as it specifies the position of the start of "Requirements and then returns the number of characters from Requirements to 3GS.
Compute start as:
Start = Position ( RawT ; "Requirements: </span>" ; 1; 1 ) + Length ( "Requirements: </span>" )
compute end as
end = Position ( RawT ; "<" ; start ; 1 )
And you can leave out the GetAsText function here as it does not affect the results produced.
Great! Works well with the Length function added - just FYI, as long as I do GetAsText.
When I do GetAsText I get: Compatible with iPhone 3GS, iPhone 4, iPhone 4S, iPod touch (4th generation), iPad 2 Wi-Fi, iPad 2 Wi-Fi + 3G, iPad (3rd generation) and iPad Wi-Fi + 4G.Requires iOS 4.0 or later.
When I do GetAsNumber I just get the numbers in the calculation stripped out: 344422334.4 (no matter whether the calculation result is a number or text)
Why would you use "getasnumber"?
I am suggesting that you use neither getastext nor getasnumber. Just remove that function call and keep the rest of your expression.
I see; yes that works also and keeps it simple...