www.icetips.com  Icetips Utilities Documentation 10/28/2015    

String Class:  GetStringBetween

Previous  Top  Next  


Prototype: (STRING pBegin, STRING pEnd, STRING pSearchString,<Long pBeginPos>, <Long pEndBeginPos>, BYTE pCaseSensitive=FALSE),STRING

 

pBeginThe string to search for to mark the beginning of the new string.  The new string starts in the character position after the pBegin is found.
pEndThe string to search for to mark the end of the new string.  The new string ends in the character position before the pEnd is found.
pSearchStringThe string to search in.
pBeginPosOptionally specify where to start searching in pSearchString to find the beginning position
pEndBeginPosOptionally specify where to start searching in pSearchString to find the beginning of the end position.
pCaseSensitiveOptionally specify if the search should be case sensitive.  Defaults to false (i.e. NOT case sensitive - all comparisons are done using UPPER()

 

ReturnsReturns the string found between pBegin and pEnd or empty string if either or neither was found or if the end position is lower than the beginning position.

 

This method takes a string and then searches for a beginning and end strings in it and returns the string between those two strings.  This is very handy for example to extract data from for example html or xml strings. 

 

Example:

 

GetServiceXMLError        PROCEDURE(STRING pXML)

ITS         ITStringClass

Err_Value   CSTRING(101)

Err_Text    CSTRING(1025)

CODE

!! (STRING pXML),STRING

IF INSTRING('<SOAP:REASON>',UPPER(pXML),1,1)

   Err_Value = ITS.GetStringBetween('<soap:Value>',             '</soap:Value>',pXML)  

   Err_Text  = ITS.GetStringBetween('<soap:Text xml:lang="en">','</soap:Text>', pXML)

   ITS.ODS('Value:  ' & Err_Value)

   ITS.ODS('Reason: ' & Err_Text)

ELSIF INSTRING('<FAULTCODE>',UPPER(pXML),1,1)

   Err_Value = ITS.GetStringBetween('<faultcode>',   '</faultcode>',   pXML)  

   Err_Text  = ITS.GetStringBetween('<faultstring>', '</faultstring>', pXML)

   ITS.ODS('Fault Code:  ' & Err_Value)

   ITS.ODS('Fault String: ' & Err_Text)

END

RETURN(Err_Text)

 

See also:

InsertString

RemoveHTML

 



Direct link to this page: http://www.icetips.com/manuals/utilities/getstringbetween_stringclass.htm