|
|
|
|
|
- Remark on the syntax "Searching substrings based on a separator"
- ExtractString and UNICODE
ExtractString (Function) In french: ExtraitChaîne 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.
Country is string = "France, Italy, Germany, Spain"
ExtractString(Country, 1, ", ")
ExtractString(Country, 2, ", ")
ExtractString(Country, 3, ", ")
ExtractString(Country, 4, ", ")
ExtractString(Country, 5, ", ")
MyString is string = "Strawberry, Raspberry, Chocolate and Banana"
ExtractString(MyString, 1, [", " , "," , " and "])
ExtractString(MyString, 2, [", " , "," , " and "])
ExtractString(MyString, 3, [", " , "," , " and "])
ExtractString(MyString, 4, [", " , "," , " and "])
Syntax
Extracting a substring based on a string separator Hide the details
<Result> = ExtractString(<Initial string> , <Rang> [, <Separator> [, <Direction of travel>]])
<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. <Rang>: entier 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. <Direction of travel>: Optional constant Direction of the search path:
| | FromBeginning (Default value) | Searches from the first to the last character of the string. | FromEnd | Searches from the last to the first character of the string. |
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.
- or 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.
Remember: the language parameters used are defined when the ChangeCharset function is called.
Related Examples:
|
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
|
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|