|
|
|
|
|
- Syntax 1: Iterating over substrings separated by a separator
- Syntaxes 2 and 3: Iterating over the occurrences of a string inside another string
- FOR ANY CHAIN, FOR ANY POSITION and Unicode
- Tip: How to get the separator?
- Tip: Iterating over an XML string
FOR ALL/FOR EACH statement (browse of strings) In french: POUR TOUT / POUR TOUS
The FOR EACH statement is used to browse strings according to different methods: - Browsing the substrings separated by a separator.
- Finding the occurrences of a string inside another string.
Note: The FOR EACH, FOR ALL statements are accepted. The FOR EACH statement will be used in this documentation but it can be replaced with FOR ALL. The FOR EACH statement can also be used to browse the .Net objects that implement the IEnumerable interface. // Retrieves the list of libraries loaded in memory LibraryList is string = ListDLL() // For each library FOR EACH STRING ALibrary OF LibraryList SEPARATED BY CR // Adds the library into the TABLE_Library table TableAddLine(TABLE_Library, ExtractString(ALibrary, 1, TAB)) END
// The "C:\MyDocuments\Exports.TXT" file contains the list // of exported products, separated by ";" // Retrieve each product ExportedProduct is string = fLoadText("C:\MyDocuments\Exports.TXT") FormerPosition is int // For each product FOR EACH POSITION CurrentPosition OF ";" IN ExportedProduct // Adds the product into ProductList ListAdd(LIST_Product, ... ExportedProduct[[FormerPosition + 1 TO CurrentPosition - 1]] // Store the position FormerPosition = CurrentPosition END
FOR EACH STRING sc1, nPosition, nCounter OF "A.B.C" SEPARATED BY "." Trace(sc1 + " - " + nPosition + " - " + nCounter) END // Returns // A - 1 - 1 // B - 3 - 2 // C - 5 - 3
s is string = "I am a sentence"+CR+"on several lines" FOR EACH STRING s2 OF s SEPARATED BY [" ",CR] Trace(s2) END // Returns // I // am // a // sentence // on // several // lines
Syntax
Browsing the substrings separated by a separator Hide the details
FOR EACH STRING <Substring> [, <Position> [, <Counter>]] OF <Initial string> [SEPARATED BY <Separator>] [<Direction>]
... END
<FOR EACH STRING>: Marks the beginning of the statement block. <Substring>: String variable containing the text of the substring. There is no need to declare this variable. <Position>: Integer variable containing the position of the substring in the string. There is no need to declare this variable. <Counter>: Integer variable containing the number of iterations. There is no need to declare this variable. <Initial string>: String containing the full text. The iteration does not take place if this string is empty. <Separator>: Optional string containing the separator of substrings (TAB by default).To specify several separators, use the following syntax: [<Separator1> , ..., <Separator N>] For example: [TAB, CR] <Direction>: Optional indicator for the iteration direction: | | FromBeginning (default value) | Browse the string from the first character to the last one. | FromEnd | Browse the string from the last character to the first one. |
Browsing the occurrences of a string inside another string Hide the details
FOR EACH POSITION <Position> OF <Search> IN <Initial String> [<Direction>]
... END
<FOR EACH POSITION>: Marks the beginning of the statement block. <Position>: Integer variable containing the current position. There is no need to declare this variable. <Search>: Sought string. <Initial string>: String containing the full text. <Direction>: Optional indicator for the iteration direction: | | FromBeginning (default value) | Browse the string from the first character to the last one. | FromEnd | Browse the string from the last character to the first one. |
Browsing the occurrences of a string inside another string Hide the details
FOR EACH POSITION <Position> OF <Search> IN <Initial String> WITH <Options>
... END
<FOR EACH POSITION>: Marks the beginning of the statement block. <Position>: Integer variable containing the current position. There is no need to declare this variable. <Search>: Sought string. <Initial string>: String containing the full text. <Options>: Indicator for the selected options (can be combined): | | FromBeginning (default value) | Browse the string from the first character to the last one. | FromEnd | Browse the string from the last character to the first one. | WholeWord | Search for the whole word | IgnoreCase | Case-insensitive search (upper/lowercase) |
Remarks Syntax 1: Iterating over substrings separated by a separator Browses all the substrings in <Initial string> separated by <Separator>. The browse is not performed if <Initial String> is an empty string. For each iteration: - <Substring> is filled with the current substring.
- <Position> contains the position of the substring inside the string.
- <Counter> contains the number of iterations performed.
The behavior is undefined if the initial string or the separator is modified during the browse. Note: If <Initial string> ends with the separator, <Substring> returns an empty string at the end. Otherwise, <Substring> corresponds to the last checked-out element. Syntaxes 2 and 3: Iterating over the occurrences of a string inside another string Finds all the occurrences of the <Search> substring in the <Initial string>. At each iteration, the position of the current substring is assigned to the <Position> variable. The behavior is undefined if the initial string or the sought string is modified during the browse. FOR ANY CHAIN, FOR ANY POSITION and Unicode <Substring>, <Initial string>, <Separator> and <Search> can correspond to: - ANSI strings.
- or Unicode strings.
However, it is not possible to use ANSI and Unicode strings in the same syntax. Tip: How to get the separator? To retrieve the separator in the loop, use the following syntax. To get the separator, simply retrieve the following character. For example: FOR EACH STRING sTempString, nPosition OF sStringIN SEPARATED BY [" ","-"] sSeparator = sStringIN[[nPosition + Length(sTempString)]] ... END
Tip: Iterating over an XML string
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|