PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Finding the character string
  • Managing the ambiguities
  • PositionOccurrence function and UNICODE
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
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
Android This function is now available for the Android applications.
New in version 15
Android This function is now available for the Android applications.
Android This function is now available for the Android applications.
Versions 17 and later
iPhone/iPad This function is now available for the iPhone/iPad applications.
New in version 17
iPhone/iPad This function is now available for the iPhone/iPad applications.
iPhone/iPad This function is now available for the iPhone/iPad applications.
Versions 18 and later
Android Widget This function is now available in Android Widget mode.
Universal Windows 10 App This function is now available in Windows Store apps mode.
New in version 18
Android Widget This function is now available in Android Widget mode.
Universal Windows 10 App This function is now available in Windows Store apps mode.
Android Widget This function is now available in Android Widget mode.
Universal Windows 10 App This function is now available in Windows Store apps mode.
Versions 21 and later
Apple Watch This function is now available in Apple Watch mode.
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
New in version 21
Apple Watch This function is now available in Apple Watch mode.
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
Apple Watch This function is now available in Apple Watch mode.
Universal Windows 10 App 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
ArrayAdd(MyArray, "an")
ArrayAdd(MyArray, "ar")
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 Hide the details

<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.
Versions 16 and later
PHP You now have the ability to use an array of strings.
New in version 16
PHP You now have the ability to use an array of strings.
PHP You now have the ability to use an array of strings.
<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
FromEndSearch performed from the last character of the string to the first one
WholeWordSearch for a whole word (enclosed in punctuation characters or in space characters)
IgnoreCaseSearch while ignoring the case (uppercase/lowercase characters) or the accented characters

Browsing the positions of a string in a sub-string Hide the details

<Result> = PositionOccurrence(<Initial String> , <String to Find> , <Search 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.
Versions 16 and later
PHP You now have the ability to use an array of strings.
New in version 16
PHP You now have the ability to use an array of strings.
PHP You now have the ability to use an array of strings.
<Search Options>: Integer constant
Browse direction:
lastRankStarts browsing the sub-strings separated by the <String to Find> from the end of the string.
previousRankResumes a browse operation started by the lastRank constant
firstRankStarts browsing the sub-strings separated by the <String to Find> from the beginning of the string.
nextRankResumes 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
FromEndSearch performed from the last character of the string to the first one
WholeWordSearch for a whole word (enclosed in punctuation characters or in space characters)
IgnoreCaseSearch 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").
WINDEVWEBDEV - Server codeReports and QueriesAndroidAndroid Widget Windows MobileUniversal Windows 10 AppJavaPHPAjaxUser code (UMC)

PositionOccurrence function 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):
  • It 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):
  • It 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.
Components
WINDEVWEBDEV - Server codeReports and Queries wd230vm.dll
Windows Mobile wp230vm.dll
WEBDEV - Browser code WDJS.DLL
Java wd230java.jar
Linux wd230vm.so
Android wd230android.jar
Minimum required version
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment