Aracılığıyla paylaş


STREXTRACT( ) Function

Retrieves a string between two delimiters.

STREXTRACT(cSearchExpression, cBeginDelim [, cEndDelim [, nOccurrence
[, nFlag]]]])

Parameters

  • cSearchExpression
    Specifies the string to search.

  • cBeginDelim
    Specifies the character that delimits the beginning of cSearchExpression.

  • cEndDelim
    Specifies the character that delimits the end of cSearchExpression.

  • nOccurrence
    Specifies at which occurrence of cBeginDelim in cSearchExpression to start the extraction.

  • nFlag
    Specify the type of controls placed on the search. The number you specify in nFlag provides a bit-value that determines options according to the following table:

    Bit

    Value (additive)

    Description

    0

    1

    Case-insensitive search

    1

    2

    End delimiter not required. Specifies that a search, which finds no occurrence of cEndDelim, returns the contents of cSearchExpression from the cBeginDelim location.

    2

    4

    Include the delimiters in the returned expression.

Returns

Character

Remarks

The default is a case sensitive search in which delimiters must be found (no nFlag value).

If cBeginDelim is an empty string, the search is conducted from the beginning of cSearchExpression to the first occurrence of cEndDelim. If cEndDelim is an empty string STREXTRACT( ) returns a string from nOccurrence of cBeginDelim to the end of cSearchExpression.

Example

CLEAR
SET PATH TO (HOME(2) + 'Data\')   &&Set path to the customer table
USE customer && any table
?cursortoxml(0,"x",1,0,2)   && Produce variable "x" that has XML of  first 2 records of table
?x         && show the XML
xmlproc(x,0)      && Parse the XML

PROCEDURE xmlproc(x as String, nLev as Integer)   as void
   LOCAL cTagName, cContents, mterm
   DO WHILE .t.
      cTagName = STREXTRACT(x,"<",">")
      IF LEN(cTagName) = 0   && no tag found
         ??' ',x   && print out raw string as contents
         EXIT
      ENDIF
      IF RIGHT(cTagName,1) = '/'   && like "<region/>"
         cTagName = LEFT(cTagName, LEN(cTagName)-1)
         cContents=""
         mterm = "<"+cTagName+"/>"   && "<region/>"
      ELSE
         mterm = "</"+cTagName+">"   && "</region>"
         cContents = STREXTRACT(x,"<"+cTagName+">", mterm,1,2)
      ENDIF
      ?REPLICATE("  ",nLev),nLev+1,PADR(cTagName,20)
      xmlproc(cContents, nLev+1)
      x = STREXTRACT(x, mterm)   && get the rest of the xml
   ENDDO

See Also

Reference

STRTRAN( ) Function

RAT( ) Function

RATC( ) Function

SUBSTR( ) Function

SUBSTRC( ) Function

LIKEC( ) Function

Other Resources

Functions

Language Reference (Visual FoxPro)