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 Description 1 Case-insensitive search 2 End delimiter not required. Specifies that a search, which finds no occurrence of cEndDelim, returns the contents of cSearchExpression from the cBeginDelim location.
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
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
STRTRAN( ) Function | RAT( ) Function | RATC( ) Function | SUBSTR( ) Function | SUBSTRC( ) Function | LIKEC( ) Function