PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
  • Finding a character string
  • Managing ambiguities
  • PositionOccurrence 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 string within another string. You can also examine all positions of a substring within a string.
It is also possible to find the Xth position of one of the strings in an array.
Versions 18 and later
Universal Windows 10 App This function is now available in Windows Store apps mode.
New in version 18
Universal Windows 10 App This function is now available in Windows Store apps mode.
Universal Windows 10 App This function is now available in Windows Store apps mode.
Versions 21 and later
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
New in version 21
Universal Windows 10 App This function is now available in Universal Windows 10 App 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
// Find 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
// Find 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
// Find 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

Finding the position of a substring within a string Hide the details

<Result> = PositionOccurrence(<Initial string> , <Search string> , <Index of occurrence to search for> [, <Search options>])
<Result>: Integer
If <Search string> is a character string, the result is the position of the first character of the occurrence to search for in the initial string or 0 if the search string is not found.
If <Search string> is an array of character strings, the result is the position of the first character of the first string found from the array of strings or 0 if no string from the array was found.
<Initial string>: Character string (with quotes)
Character string where the search will be performed (maximum size: 2 GB).
<Search string>: Character string (with quotes) or Array of strings
This parameter can correspond to:
  • The string to be searched for in the initial string.
  • An array of strings to be searched for in the initial string.
<Index of occurrence to search for>: Integer
Number of the occurrence of <Search string>. <Result> will contain the position of this occurrence.
If this parameter is less than 1, <Result> is set to 0.
If the value of this parameter is greater than the number of characters in <Initial string>, <Result> is equal to 0.
<Search options>: Optional constant
Indicates the search direction and the search options:
FromBeginning
(Default value)
Searches from the first to the last character of the string
FromEndSearches from the last to the first character of the string
WholeWordSearches for a whole word (between punctuation characters or spaces)
IgnoreCaseCase and accent insensitive search (ignores uppercase/lowercase differences)

Examining the positions of a substring in a string Hide the details

<Result> = PositionOccurrence(<Initial string> , <Search string> , <Browse options> [, <Search options>])
<Result>: Integer
If <Search string> is a character string, the result is the position of the first occurrence (depending on the search direction) in the initial string or 0 when the search has been completed.
If <Search string> is an array of strings, the result is the position of the first character of the previous or next occurrence (depending on the search direction) in the array of strings or 0 if the search has been completed.
<Initial string>: Character string (with quotes)
Character string where the search will be performed (maximum size: 2 GB).
<Search string>: Character string (with quotes) or Array of strings
This parameter can correspond to:
  • The string to be searched for in the initial string.
  • An array of strings to be searched for in the initial string.
<Browse options>: Integer constant
Browse direction:
lastRankStarts searching for substrings separated by the specified <Search string> from the end of the string.
previousRankContinues the search started with lastRank
firstRankStarts searching for substrings separated by the specified <Search string> from the beginning of the string.
nextRankContinues the search started with firstRank
<Search options>: Optional constant
Indicates the search direction and the search options:
FromBeginning
(Default value)
Searches from the first to the last character of the string
FromEndSearches from the last to the first character of the string
WholeWordSearches for a whole word (between punctuation characters or spaces)
IgnoreCaseCase insensitive search (ignores uppercase/lowercase differences).
Remarks

Finding a character string

The search is case sensitive by default: the search string must have the same case as the substring to find in the string. To perform a case-insensitive search, use the IgnoreCase constant.

Managing ambiguities

When the search strings are substrings of other strings 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").
WINDEVUniversal Windows 10 AppJavaUser code (UMC)

PositionOccurrence and UNICODE

<Initial string> and <Search string> 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 to buffers and the operation is performed with buffers.
  • If the first condition is not met and there is at least one Unicode string, all the strings are converted to Unicode and the operation is performed in Unicode (the conversion is performed with the current character set, if necessary).
  • Otherwise, the operation is performed in Ansi.
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 to buffers and the operation is performed with buffers.
  • Otherwise, the operation is performed in Unicode.
For more details on UNICODE, see Managing UNICODE.
Reminder: The linguistic parameters used are defined during the call to ChangeCharset.
Component: wd260vm.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Exemplo
https://forum.pcsoft.fr/fr-FR/pcsoft.br.windev/3239-procedure-com-indirection-para-selecionar-registro-uma-grid-3240/read.awp
BOLLER
24 Jun. 2019