PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
  • Remark on the syntax "Searching substrings based on a separator"
  • ExtractString 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
Allows you to:
  • extract a substring from a string based on a specified string separator.
  • search for substrings in a string based on a specified string separator.
Remarks:
  • Searching for substrings takes less time than extracting substrings.
  • You have the ability to use an array of separators. This allows you to use several different separators at the same time.
Use cases:
  • extract data read in an external file,
  • extract the information returned by HListFile or HListKey,
  • extract data from a list containing different data on the same line.
Example
Country is string = "France, Italy, Germany, Spain"
ExtractString(Country, 1, ", ")   // Returns "France"
ExtractString(Country, 2, ", ")   // Returns "Italy"
ExtractString(Country, 3, ", ")   // Returns "Germany"
ExtractString(Country, 4, ", ")   // Returns "Spain"
ExtractString(Country, 5, ", ")   // Returns EOT
MyString is string = "Strawberry, Raspberry, Chocolate and Banana"
ExtractString(MyString, 1, [", " , "," , " and "]) // Returns "Strawberry"
ExtractString(MyString, 2, [", " , "," , " and "]) // Returns "Raspberry"
ExtractString(MyString, 3, [", " , "," , " and "]) // Returns "Chocolate"
ExtractString(MyString, 4, [", " , "," , " and "]) // Returns "Banana"
WEBDEV - Server codePHPAjaxStored procedures
// Search for all the substrings
Country is string = "France, Italy, Germany, Spain"
SubString is string = ExtractString(Country, firstRank, ", ")
WHILE SubString <> EOT
Trace(SubString) // Returns "France", "Italy", "Germany", "Spain"
SubString = ExtractString(Country, nextRank, ", ")
END
WEBDEV - Server codeStored procedures
// Search for all the substrings
// The separators are in an array
sString is string = "Strawberry, Raspberry<br>Lemon<br>Chocolate and Banana"
sResult is string = ExtractString(sString, firstRank, [", " , " and ", "<br>"])
WHILE sResult <> EOT
Trace(sResult)
sResult = ExtractString(sString, nextRank, [", " , " and ", "<br>"])
END
Syntax

Extracting a substring based on a string separator Hide the details

<Result> = ExtractString(<Initial string> , <Index> [, <Separator> [, <Search direction>]])
<Result>: Character string
Corresponds to:
  • The substring between the separator at <Index> - 1 and the separator at <Index> if <Search direction> is not specified or is equal to FromBeginning.
  • The substring between the separator at <Index> - 1 and the separator at <Index> from the end of the string if <Search direction> corresponds to FromEnd.
  • The entire <Initial string> if <Initial string> contains no <Separator> and <Index> is equal to 1.
  • The EOT constant if <Index> is greater than the number of separators in the string.
<Initial string>: Character string (with quotes)
Character string (up to 2 GB) containing the string to extract.
<Index>: Integer
Position of the substring to be extracted. For example, if the separator is a TAB and <Index> is equal to 2, the substring will be extracted between the first and second TAB.
<Separator>: Optional character string (with quotes) or optional array of strings
This parameter can correspond to:
  • The string that delimits the substrings. This string is not included in the result. This separator is case sensitive.
  • An array of strings. The different strings in the array delimit the substrings. The separators are not included in the result. These separators are case sensitive.
If this parameter is not specified, the default separator is TAB.
<Search direction>: Optional constant
Search direction:
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
WEBDEV - Server codeWEBDEV - Browser codePHPAjaxStored procedures

Searching substrings based on a separator Hide the details

<Result> = ExtractString(<Initial string> , <Search options> [, <Separator>])
<Result>: Character string
Corresponds to:
  • the next or previous substring according to the specified search direction. <Result> does not contain separators.
  • the EOT constant at the end of the search.
<Initial string>: Character string (with quotes)
Character string (up to 2 GB) containing the string to extract.
<Search options>: Integer constant
Search direction:
lastRankStarts searching for substrings separated by the specified separators from the end of the string.
previousRankContinues the search started with lastRank
firstRankStarts searching for substrings separated by the specified separators from the beginning of the string.
nextRankContinues the search started with firstRank
<Separator>: Optional character string (with quotes) or optional array of strings
This parameter can correspond to:
  • The string that delimits the substrings. This string is not included in the result. This separator is case sensitive.
  • An array of strings. The different strings in the array delimit the substrings. The separators are not included in the result. These separators are case sensitive.
If this parameter is not specified, the default separator is TAB.
Remarks

Remark on the syntax "Searching substrings based on a separator"

  • This type of search can only be used on constant strings. Therefore, an element of the project (variable, control, item, etc.) must be used as initial string.
  • When a search is started with the firstRank or lastRank constants, the search information is stored in memory until all the substrings have been examined. Therefore, this type of search should be used only when all the substrings are to be examined.

ExtractString and UNICODE

<Initial string> and <Separator> can both 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 to buffers and the operation is performed with buffers.
  • If the first condition is not met and there is at least one Unicode string, all the strings are converted to Unicode and the operation is performed in Unicode (the conversion is performed with the current character set, if necessary).
  • Otherwise, the operation is performed in Ansi.
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 to buffers and the operation is performed with buffers.
  • Otherwise, the operation is performed in Unicode.
For more details on UNICODE, see Managing UNICODE.
Reminder: The linguistic parameters used are defined during the call to ChangeCharset.
Related Examples:
The standard functions on strings Unit examples (WINDEV): The standard functions on strings
[ + ] Using the main functions for handling character strings:
- Position and PositionOccurrence
- Replace
- StringBuild
- Left, Right, Middle
- ExtractString
Component: wd260vm.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment