PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
New WINDEV, WEBDEV, WINDEV Mobile 25 feature!
  • Remark on the syntax for browsing through substrings between separators
  • ExtractStringBetween and UNICODE
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
ExtractStringBetween (Function)
In french: ExtraitChaineEntre
Allows you to:
  • extract a substring between two given separators from a character string.
  • browse through substrings between two given separators in a character string.
For example, this function allows you to extract data between two tags in HTML, XML or JSON.
Remarks:
  • Browsing through substrings takes less time than extracting substrings.
  • You can use arrays of separators. This allows you to use several pairs of separators at the same time.
Example
Country is string = [
<country>France</country><country>Italy</country>
<country>Germany</country><country>Spain</country>
]
ExtractStringBetween(Country, 1, "<country>", "</country>")   // Returns "France"
ExtractStringBetween(Country, 2, "<country>", "</country>")   // Returns "Italy"
ExtractStringBetween(Country, 3, "<country>", "</country>")   // Returns "Germany"
ExtractStringBetween(Country, 4, "<country>", "</country>")   // Returns "Spain"
ExtractStringBetween(Country, 5, "<country>", "</country>")   // Returns EOT
MyString is string = [
<red fruit>Strawberry</red fruit>
<red fruit>Raspberry</red fruit>
<exotic fruit>Cacao</exotic fruit>
<exotic fruit>Banana</exotic fruit>
]
ExtractStringBetween(MyString, 1, ["<red fruit>" , "<exotic fruit>"], ...
["</red fruit>" , "</exotic fruit>"]) // Returns "Strawberry"
ExtractStringBetween(MyString, 2, ["<red fruit>" , "<exotic fruit>"], ...
 ["</red fruit>" , "</exotic fruit>"]) // Returns "Raspberry"
ExtractStringBetween(MyString, 3, ["<red fruit>" , "<exotic fruit>"], ...
 ["</red fruit>" , "</exotic fruit>"]) // Returns "Cacao"
ExtractStringBetween(MyString, 4, ["<red fruit>" , "<exotic fruit>"], ...
 ["</red fruit>" , "</exotic fruit>"]) // Returns "Banana"
// Browse all the sub-strings
Country is string = [
<country>France</country><country>Italy</country>
<country>Germany</country><country>Spain</country>
]
SubString is string = ExtractStringBetween(Country, firstRank, "<country>", "</country>")
WHILE SubString <> EOT
Trace(SubString) // Returns "France", "Italy", "Germany", "Spain"
SubString = ExtractStrinBetween(Country, nextRank, "<country>", "</country>")
END
// Browse all the sub-strings
// The separators are in arrays
sString is string = [
<red fruit>Strawberry</red fruit>
<red fruit>Raspberry</red fruit>
<exotic fruit>Cacao</exotic fruit>
<exotic fruit>Banana</exotic fruit>
]
sResult is string = ExtractStringBetween(sString, firstRank, ["<red fruit>" , ...
 "<exotic fruit>"], ["</red fruit>" , "</exotic fruit>"])
WHILE sResult <> EOT
Trace(sResult)
sResult = ExtractStringBetween(sString, nextRank, ["<red fruit>" , "<exotic fruit>"], ...
 ["</red fruit>" , "</exotic fruit>"])
END
Syntax

Extracting a substring between two given separators from a string Hide the details

<Result> = ExtractStringBetween(<Initial string> , <Rank> , <Start separator> [, <End separator> [, <Options>]])
<Result>: Character string
Corresponds to:
  • The substring between <Start separator> of <Rank> and <End separator> if the FromEnd constant is not specified.
  • The substring between <Start separator> of <Rank> from the end of the string and the next end separator if the FromEnd constant is specified.
  • The EOT constant in one of the following cases:
    • if <Rank> is greater than the number of start separators followed by end separators in the string,
    • if all separators are empty strings ("").
<Initial string>: Character string (with quotes)
Character string (up to 2 GB) containing the string to extract.
<Rank>: Integer
Order number of start separator followed by an end separator.
Remark: a start separator is not taken into account if there is no end separator between it and the previous start separator, unless the following conditions are met:
  • <Rank> is set to 1,
  • the FromEnd option is not specified.
<Start separator>: Character string (with quotes) or Array of strings
This parameter can correspond to:
  • The string that delimits the beginning of substrings. This string is not included in the result.
  • An array of strings. The different strings in the array allow delimiting the beginning of substrings. The separators are not included in the result.
<End separator>: Optional character string (with quotes) or optional array of strings
This parameter can correspond to:
  • The string that delimits the end of substrings. This string is not included in the result.
  • An array of strings. The different strings found in the array are used to delimit the sub-strings. The separators are not included in the result.
If this parameter is not specified, the end separator will be identical to <Start separator>.
<Options>: Optional Integer constant
Browse direction and search characteristics:
FromBeginning
(Default value)
Search performed from the first character of the string to the last one.
FromEndSearch performed from the last character of the string to the first one.
WholeWordSearch for a whole word (enclosed in punctuation characters or in space characters).
Linux This constant has no effect.
IgnoreCaseSearch while ignoring the case (uppercase/lowercase characters) or the accented characters.
Linux This constant has no effect.

Browse through substrings between two given separators in a character string Hide the details

<Result> = ExtractStringBetween(<Initial string> , <Browse options> , <Start separator> [, <End separator> [, <Options>]])
<Result>: Character string
Corresponds to:
  • the next or previous sub-string according to the selected browse. <Result> contains no separator.
  • the EOT constant at the end of the browse.
<Initial string>: Character string (with quotes)
Character string (up to 2 GB) containing the string to extract.
<Browse options>: Integer constant
Browse direction:
lastRankStarts browsing through substrings separated by the specified separators from the end of the string.
previousRankResumes a browse operation started by the lastRank constant
firstRankStarts browsing through substrings separated by the specified separators from the beginning of the string.
nextRankResumes a browse operation started by the firstRank constant
<Start separator>: Character string (with quotes) or Array of strings
This parameter can correspond to:
  • The string that delimits the beginning of substrings. This string is not included in the result.
  • An array of strings. The different strings in the array allow delimiting the beginning of substrings. The separators are not included in the result.
<End separator>: Optional character string (with quotes) or optional array of strings
This parameter can correspond to:
  • The string that delimits the end of substrings. This string is not included in the result.
  • An array of strings. The different strings found in the array are used to delimit the sub-strings. The separators are not included in the result.
If this parameter is not specified, the end separator will be identical to <Start separator>.
<Options>: Optional Integer constant
Search characteristics:
WholeWordSearch for a whole word (enclosed in punctuation characters or in space characters).
IgnoreCaseSearch while ignoring the case (uppercase/lowercase characters) or the accented characters.
Linux This parameter is not available. The search is case sensitive. The sought string does not necessarily correspond to a whole world: this string can be part of a word.
Remarks

Remark on the syntax for browsing through substrings between separators

  • This type of browse operates on constant strings only. Therefore, a project element (variable, control, item, ...) must necessarily be used as initial string.
  • When a browse is started with the firstRank or lastRank constants, the browse information is stored in memory as long as all the extracted sub-strings have not been browsed. Therefore, this type of browse should be used only when all the sub-strings must be processed.

ExtractStringBetween and UNICODE

<Initial string>, <Start separator> and <End separator> can correspond to:
  • ANSI strings.
  • UNICODE strings.
  • buffers.
You have the ability to use ANSI strings, Unicode strings and buffers in the different parameters of the function.
The following conversion rule is used for the Ansi systems (Windows or Linux):
  • If at least one of the strings is a buffer, all the strings are converted into buffers and the operation is performed with buffers,
  • otherwise, if at least one of the strings is in Unicode format, all the strings are converted into Unicode and the operation is performed in Unicode,
  • otherwise, the operation is performed in Ansi format.
The following conversion rule is used for the Unicode systems (Windows CE):
  • If at least one of the strings is a buffer, all the strings are converted into buffers and the operation is performed with buffers,
  • otherwise, the operation is performed in Unicode.
Remark: If the result on an ANSI string is assigned to a UNICODE string (and conversely), the conversion will be implicitly performed.
See Managing UNICODE for more details.
Component : wd250vm.dll
Minimum version required
  • Version 25
This page is also available for…
Comments
Click [Add] to post a comment