StrExtract Function | |
-- todo --
Retrieves a string between two delimiters.
Namespace:
XSharp.VFP
Assembly:
XSharp.VFP (in XSharp.VFP.dll) Version: 2.21
Syntax FUNCTION StrExtract(
cSearchExpression,
cBeginDelim,
cEndDelim,
nOccurrence,
nFlag
) AS STRING CLIPPER
[ClipperCallingConventionAttribute(new string[] { ... })]
public static string StrExtract(
Usual cSearchExpression = default,
Usual cBeginDelim = default,
Usual cEndDelim = default,
Usual nOccurrence = default,
Usual nFlag = default
)
Request Example
View SourceParameters
- cSearchExpression (Optional)
- Type: Usual
Specifies the string to search.
- cBeginDelim (Optional)
- Type: Usual
Specifies the character that delimits the beginning of cSearchExpression.
- cEndDelim (Optional)
- Type: Usual
Specifies the character that delimits the end of cSearchExpression.
- nOccurrence (Optional)
- Type: Usual
Specifies at which occurrence of cBeginDelim in cSearchExpression to start the extraction.
- nFlag (Optional)
- Type: Usual
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. |
Return Value
Type: String
Character or Varbinary.br
The Result data type is derived by the first parameter data type.
Return Value
Type:
StringRemarks
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.
Examples 1Clear
2Set PATH TO (HOME(2) + 'Data\')
3Use customer
4?cursortoxml(0,"x",1,0,2)
5?x
6xmlproc(x,0)
7PROCEDURE xmlproc(x as String, nLev as Integer) as void
8LOCAL cTagName, cContents, mterm
9DO WHILE .t.
10cTagName = StrExtract(x,"<",">")
11IF LEN(cTagName) = 0
12??' ',x
13EXIT
14ENDIF
15IF RIGHT(cTagName,1) = '/'
16cTagName = LEFT(cTagName, LEN(cTagName)-1)
17cContents=""
18mterm = "<"+cTagName+"/>"
19ELSE
20mterm = "</"+cTagName+">"
21cContents = StrExtract(x,"<"+cTagName+">", mterm,1,2)
22ENDIF
23?REPLICATE(" ",nLev),nLev+1,PADR(cTagName,20)
24xmlproc(cContents, nLev+1)
25x = StrExtract(x, mterm)
26ENDDO
See Also