|
- Syntax 1: Browsing the sub-strings separated by a separator
- Syntax 2 and 3: Browsing the occurrences of a string inside another one
- FOR EACH STRING, FOR EACH POSITION and UNICODE
- Tip: How to get the separator?
- Tip: Browsing an XML string
FOR ALL/FOR EACH statement (browse of strings) In french: POUR TOUT / POUR TOUS
// 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
Versions 19 and later
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
New in version 19
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
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 sub-strings separated by a separator Hide the details
FOR EACH STRING <Sub-string> [, <Position> [, <Counter>]] OF <Initial String> [SEPARATED BY <Separator>] [<Direction>]
... END
<FOR EACH STRING>: Marks the beginning of statement block. <Sub-string>: String variable containing the text of the sub-string. There is no need to declare this variable. <Position>: Integer variable containing the position of the sub-string 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 sub-strings are not browsed if this string is empty. <Separator>: Optional string containing the separator of sub-strings (TAB by default). Versions 19 and laterTo specify several separators, use the following syntax:
[<Separator1> , ..., <Separator N>]
For example: [TAB, CR] New in version 19To specify several separators, use the following syntax:
[<Separator1> , ..., <Separator N>]
For example: [TAB, CR] To specify several separators, use the following syntax:
[<Separator1> , ..., <Separator N>]
For example: [TAB, CR] <Direction>: Optional indicator for the browse 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 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 browse 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 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 | Search while ignoring the case (uppercase/lowercase characters) |
Remarks Syntax 1: Browsing the sub-strings separated by a separator Browses all the sub-strings of <Initial String> separated by <Separator>. The browse is not performed if <Initial String> is an empty string. For each iteration: - <Sub-string> is filled with the current sub-string.
- <Position> contains the position of the sub-string 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. Remark: If <Initial String> ends with the separator, <Sub-string> returns an empty string at the end. Otherwise, <Sub-string> corresponds to the last checked-out element. Syntax 2 and 3: Browsing the occurrences of a string inside another one Browses all the positions of <Search> in <Initial String>. For each iteration, the <Position> variable is assigned with the position of the current sub-string. The behavior is undefined if the initial string or the sought string is modified during the browse. FOR EACH STRING, FOR EACH POSITION and UNICODE <Sub-string>, <Initial String>, <Separator> and <Search> can correspond to: - ANSI strings.
- UNICODE strings.
However, the ANSI strings and the UNICODE strings cannot be used in the same syntax. Tip: How to get the separator? To retrieve the separator in the loop, use the following syntax that allows you to find out the position of the separator. To find out the separator, all you have to do is retrieve the following character. For example:
FOR EACH STRING sTempString, nPosition OF sStringIN SEPARATED BY [" ","-"] sSeparator = sStringIN[[nPosition + Length(sTempString)]] ... END
Tip: Browsing an XML string To browse an XML file, XMLExecuteXPath must be run before using the "FOR EACH" syntax.
This page is also available for…
|
|
|
| |
| Exemplo Tirando Enter Observação |
|
| Exemplo Tirando Enter Observação
//Vou Ler o Campo Observação e Tirar os Cr (Enter) //I will read the field note and taking the cr(Enter) //Je vais lire la note de terrain et prenant le CR (Entrée)
EDT_resultado="" FOR EACH STRING s_resultado1 OF EDT_Observacao SEPAREE BY CR EDT_resultado+=s_resultado1 EDT_resultado+=" " END
//Blog com Video e Exemplo http://windevdesenvolvimento.blogspot.com.br/2016/06/curso-windev-string-013-tirando-enter.html https://www.youtube.com/watch?v=0FVxViLlDYc |
|
|
|
| |
| |
| |
| |
| |
| |
| | |
| |