PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • 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
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
The FOR EACH statement is used to browse strings according to different methods:
  • Browsing the sub-strings separated by a separator.
  • Browsing the occurrences of a string inside another one.
Note: The FOR ALL, FOR EACH statements are accepted. In this documentation, we will be using the FOR EACH statement but it can be replaced by FOR ALL.
Versions 15 and later
The FOR EACH statement can also be used to browse the .Net objects that implement the IEnumerable interface.
New in version 15
The FOR EACH statement can also be used to browse the .Net objects that implement the IEnumerable interface.
The FOR EACH statement can also be used to browse the .Net objects that implement the IEnumerable interface.
Versions 17 and later
iPhone/iPad This feature is available for the iPhone/iPad applications.
New in version 17
iPhone/iPad This feature is available for the iPhone/iPad applications.
iPhone/iPad This feature is available for the iPhone/iPad applications.
Versions 18 and later
Universal Windows 10 App This feature is available in Windows Store apps mode.
Android Widget This feature is available in Android Widget mode.
New in version 18
Universal Windows 10 App This feature is available in Windows Store apps mode.
Android Widget This feature is available in Android Widget mode.
Universal Windows 10 App This feature is available in Windows Store apps mode.
Android Widget This feature is available in Android Widget mode.
Versions 21 and later
Universal Windows 10 App This feature is available in Universal Windows 10 App mode.
Apple Watch This feature is available in Apple Watch mode.
New in version 21
Universal Windows 10 App This feature is available in Universal Windows 10 App mode.
Apple Watch This feature is available in Apple Watch mode.
Universal Windows 10 App This feature is available in Universal Windows 10 App mode.
Apple Watch This feature is available in Apple Watch mode.
Example
// 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 later
To specify several separators, use the following syntax:
[<Separator1> , ..., <Separator N>]
For example: [TAB, CR]
New in version 19
To 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.
FromEndBrowse 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.
FromEndBrowse 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.
FromEndBrowse the string from the last character to the first one.
WholeWordSearch for the whole word
IgnoreCaseSearch 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.
Note: 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.
See Managing the UNICODE format for more details.

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.
Minimum version required
  • Version 10
This page is also available for…
Comments
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
De matos AMARILDO
14 Jun. 2016