Navigation:  ThinBASIC Language > thinBasic Functions > String functions >

GRABF$

Previous pageReturn to chapter overviewNext page

 

Description

 

FAST version of GRAB$ function working on scalar string variable only!

Returns a string delimited by StrDelim_1 and and StrDelim_2

 

Syntax

 

s = GRABF$(StringVariable, StrDelim_1, StrDelim_2 [, Index])

 

Returns

 

String

 

Parameters

 

Name

Type

Optional

Meaning

StringVariable

Variable

No

IMPORTANT: a scalar string variable.

 

The string to parse.

StrDelim_1

String

No

First delimiter

StrDelim_2

String

No

Second delimiter

Index

Numeric

Yes

The delimited field number to return.

If omitted, 1 is assumed.

 

Remarks

 

Restrictions

 

See also

 

PATCH$

 

Examples

 

#MinVersion 1.10.4

 

uses "Console"

 

PrintL "-----------------------------------------------------------------" in %CCOLOR_FYELLOW

PrintL "---Load XML from https://www.w3schools.com/xml/cd_catalog.xml ---" in %CCOLOR_FYELLOW

PrintL "---Using winhttp.winhttprequest.5.1 COM Object                ---" in %CCOLOR_FYELLOW

PrintL "---And parse string buffer (XML) using GRAB$                  ---" in %CCOLOR_FYELLOW

PrintL "-----------------------------------------------------------------" in %CCOLOR_FYELLOW

PrintL "---WinHttpRequest object reference:                           ---" in %CCOLOR_FYELLOW

PrintL "---https://msdn.microsoft.com/en-us/library/windows/desktop/aa384106(v=vs.85).aspx" in %CCOLOR_FYELLOW

PrintL "-----------------------------------------------------------------" in %CCOLOR_FYELLOW

 

iDispatch oHTTP

String    sXML

string    sCD

string    sTitle

long      lCDIndex

 

printl "Creating winhttp.winhttprequest.5.1 object ..."

ohttp = NewCom("winhttp.winhttprequest.5.1")

 

if IsComObject(oHttp) then

 

  printl "Object creation was ok"

  printl "Now Getting XML ..." in %CCOLOR_FYELLOW

 

  '---Open connection, send request, get response

  oHTTP.Open("GET""https://www.w3schools.com/xml/cd_catalog.xml")

  oHTTP.Send

  sXML = oHTTP.Responsetext

 

  PrintL "All done." in %CCOLOR_FYELLOW

  PrintL "---Press a key to print XMl content---" in %CCOLOR_FYELLOW

  WaitKey

 

  '---Print XML content

  printl sXML

  

  printl "---Now Parsing XML using GRAB$..." in %CCOLOR_FYELLOW

  PrintL "---Press a key to start---" in %CCOLOR_FYELLOW

  WaitKey

  

  '---Loop till we have a <CD> node

  lCDIndex = 1

  Do

    '---Grab all <CD></CD> nodes

    sCD = grabf$(sXML, "<CD>""</CD>", lCDIndex)

    

    if len(sCD) Then

      '---From <CD> node get <TITLE> node

      sTitle = grabf$(sCD, "<TITLE>""</TITLE>")

 

      printl lCDIndex, "CD Title:", sTitle  in %CCOLOR_FCYAN

      printl $tab"<CD> node content"  in %CCOLOR_FLIGHTMAGENTA

      printl sCD

 

      incr lCDIndex

    end If

    

  loop while len(sCD)

  

  '---Release object

  oHttp = nothing

  

Else

  PrintL "Error creating winhttprequest.5.1 COM Object" in %CCOLOR_FLIGHTRED

end if

 

PrintL "---All done, press a key to end---" in %CCOLOR_FYELLOW

 

WaitKey