This content comes from an automatic translation.
• Finding the character string
• Managing the ambiguities
• Function PositionOccurrence and UNICODE
WINDEV
WEBDEV
WINDEV Mobile
Others
PositionOccurrence (Function)
In french: PositionOccurrence
Finds the Xth position of a character string in a character string. You also have the ability to browse all the positions of a sub-string in a string.
You can also find the Xth position of one of the character strings found in an array.
Versions 15 and later
This function is now available for Android applications.
New in version 15
This function is now available for Android applications.
This function is now available for Android applications.
Versions 17 and later
This function is now available for iPhone/iPad applications.
New in version 17
This function is now available for iPhone/iPad applications.
This function is now available for iPhone/iPad applications.
Versions 18 and later
This function is now available in Android Widget mode.
This function is now available in Windows Store apps mode.
New in version 18
This function is now available in Android Widget mode.
This function is now available in Windows Store apps mode.
This function is now available in Android Widget mode.
This function is now available in Windows Store apps mode.
Versions 21 and later
This function is now available in Apple Watch mode.
This function is now available in Universal Windows 10 App mode.
New in version 21
This function is now available in Apple Watch mode.
This function is now available in Universal Windows 10 App mode.
This function is now available in Apple Watch mode.
This function is now available in Universal Windows 10 App mode.
Example
n = PositionOccurrence("Antananarivo, Madagascar", "g", 1) // Returns 19
n = PositionOccurrence("Antananarivo, Madagascar", "zen", 1) // Returns 0
n = PositionOccurrence("Antananarivo, Madagascar", "n", 1) // Returns 2
n = PositionOccurrence("Antananarivo, Madagascar", "n", 2) // Returns 5
// Find the third "a" starting from the end:
// The position is given from the beginning
n = PositionOccurrence("Antananarivo, Madagascar", "a", 3, FromEnd)
// Returns 18
// Find an array of strings
n = PositionOccurrence("Antananarivo, Madagascar", ["an", "ar"], 1) // Returns 4
n = PositionOccurrence("Antananarivo, Madagascar", ["an", "ar"], 2) // Returns 6
n = PositionOccurrence("Antananarivo, Madagascar", ["an", "ar"], 3) // Returns 8
n = PositionOccurrence("Antananarivo, Madagascar", ["an", "ar"], 4) // Returns 23
// Browse the positions of all the letters "a" and "A"
MyString is string = "Antananarivo, Madagascar"
MyPosition is int = PositionOccurrence(MyString, "a", firstRank, IgnoreCase)
WHILE MyPosition <> 0
Trace(MyPosition) // Returns 1, 4, 6, 8, 16, 18, 20, 23
MyPosition = PositionOccurrence(MyString, "a", nextRank, IgnoreCase)
END
// Browse the positions of all the letters "a", "A", "r" and "R"
MyString is string = "Antananarivo, Madagascar"
MyPosition is int = PositionOccurrence(MyString, ["a", "r"], firstRank, IgnoreCase)
WHILE MyPosition <> 0
Trace(MyPosition) // Returns 1, 4, 6, 8, 9, 16, 18, 20, 23, 24
MyPosition = PositionOccurrence(MyString, ["a", "r"], nextRank, IgnoreCase)
END
// Browse the positions of all the letters "an" and "ar"
MyString is string = "Antananarivo, Madagascar"
MyArray is array of 2 strings
MyPosition is int = PositionOccurrence(MyString, MyArray, firstRank, IgnoreCase)
WHILE MyPosition <> 0
Trace(MyPosition) // Returns 1, 4, 6, 8, 23
MyPosition = PositionOccurrence(MyString, MyArray, nextRank, IgnoreCase)
END
Syntax

Position of a sub-string

<Result> = PositionOccurrence(<Initial string> , <String to find> , <Rank of Sought Occurrence> [, <Search options>])
<Result>: Integer
If <String to Find> is a character string, position of the first character of the sought occurrence in the initial string or 0 if the sought string is not found.
If <String to Find> is an array of character strings, position of the first character of the first found string from the array of string or 0 if no array string is found.
<Initial string>: Character string (with quotes)
Character string where the search will be performed (maximum size: 2 GB).
<String to find>: Character string (with quotes) or array of character strings
This parameter can correspond to:
• The character string to find in the initial string.
• An array of strings to find in the initial string.
<Rank of Sought Occurrence>: Integer
Number of the occurrence of <String to Find>. <Result> will contain the position of this occurrence.
If this parameter is less than 1, <Result> is set to 0.
If this parameter is greater than the number of character found in <Initial String>, <Result> is equal to 0.
<Search options>: Optional constant
Indicates the search direction and the search options:
 FromBeginning(Default value) Search performed from the first character of the string to the last one FromEnd Search performed from the last character of the string to the first one WholeWord Search for a whole word (enclosed in punctuation characters or in space characters) IgnoreCase Search while ignoring the case (uppercase/lowercase characters) or the accented characters

Browsing the positions of a string in a sub-string

<Result> = PositionOccurrence(<Initial string> , <String to find> , <Browse options> [, <Search options>])
<Result>: Integer
If <String to Find> is a character string, position of the first character of the next or previous sought occurrence (depending on the direction) in the initial string or 0 when the end has been reached.
If <String to Find> is an array of character strings, position of the first character of the previous or next occurrence (depending on the direction) among the array of string or 0 if the end has been reached.
<Initial string>: Character string (with quotes)
Character string where the search will be performed (maximum size: 2 GB).
<String to find>: Character string (with quotes) or array of character strings
This parameter can correspond to:
• The character string to find in the initial string.
• An array of strings to find in the initial string.
<Browse options>: Integer constant
Browse direction:
 lastRank Starts browsing the sub-strings separated by the from the end of the string. previousRank Resumes a browse operation started by the lastRank constant firstRank Starts browsing the sub-strings separated by the from the beginning of the string. nextRank Resumes a browse operation started by the firstRank constant
<Search options>: Optional constant
Indicates the search direction and the search options:
 FromBeginning(Default value) Search performed from the first character of the string to the last one FromEnd Search performed from the last character of the string to the first one WholeWord Search for a whole word (enclosed in punctuation characters or in space characters) IgnoreCase Search while ignoring the case (uppercase/lowercase characters)
Remarks

Finding the character string

The search is case sensitive by default: the sought string and the string to find must have the same case. To ignore the case, use the IgnoreCase constant.

Managing the ambiguities

When the strings to find are sub-strings of other strings found in the array, the longest strings are taken into account.
Example: If the ["after", "afternoon", "afterward"] array of strings must be found in "Come this afternoon after the game", the first occurrence found will be "afternoon" (and not "after").

Function PositionOccurrence and UNICODE

<Initial String> and <String to Find> 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 into buffers and the operation is performed with buffers
• otherwise, if at least one of the strings is in Unicode format, all the strings are converted into Unicode and the operation is performed in Unicode,
• otherwise, the operation is performed in Ansi format.
The following conversion rule is used for the Unicode systems (Windows CE):
• If at least one of the strings is a buffer, all the strings are converted into buffers and the operation is performed with buffers,
• otherwise, the operation is performed in Unicode.
See Managing the UNICODE format for more details.
Component : wd250vm.dll
Minimum version required
• Version 9