ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / String functions
  • 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/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
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"
WINDEVWEBDEV - Server codeReports and QueriesUniversal Windows 10 AppAndroidAndroid Widget JavaUser code (UMC)PHPAjaxStored 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
WINDEVWEBDEV - Server codeReports and QueriesUniversal Windows 10 AppAndroidAndroid Widget JavaUser code (UMC)Stored 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
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 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)
Searches from the first to the last character of the string.
FromEndSearches from the last to the first character of the string.
WINDEVWEBDEV - Server codeWEBDEV - Browser codeReports and QueriesUniversal Windows 10 AppAndroidAndroid Widget iPhone/iPadApple WatchJavaUser code (UMC)PHPAjaxStored 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
Character string (up to 2 GB) containing the string to extract.
<Search options>: Integer constant
Search direction:
firstRankStarts searching for substrings separated by the specified separators from the beginning of the string.
lastRankStarts searching for substrings separated by the specified separators from the end of the string.
nextRankContinues the search started with firstRank
previousRankContinues the search started with lastRank
<Separator>: Optional character string 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 conversion rule used for Unicode systems is as follows:
  • 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: wd290vm.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
ExtractString exemplo 1
Eu faria assim:

ArrNomes is array of string
X is Int=0
N_exclama is int = stringcount(texto, “!”)
Nome is string
Loop(N_exclama)
X++
Nome=extractString(texto, x, “!”) //começo pro fim
Add(ArrNomes, Nome)
End
Boller
28 Nov. 2023

Last update: 06/22/2023

Send a report | Local help