PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • Finding the character string
  • Unicode/Ansi
  • Characters taken into account for the punctuation and the spaces
  • Various
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 position of a character string in another character string (or in a Buffer).
You also have the ability to find the 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 16 and later
Universal Windows 10 App This function is now available for the Windows Phone applications.
New in version 16
Universal Windows 10 App This function is now available for the Windows Phone applications.
Universal Windows 10 App This function is now available for the Windows Phone 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 is int
MyString is string = "What a wonderful World"
n = Position(MyString, "won", 1, FromBeginning)
// Returns 8 (position of "w" in "wonderful")
n = Position(MyString, "XXX")
// Returns 0 (no "XXX" found in the string)
n = Position(MyString, "l", 0, FromEnd)
// Returns 21 (position of "l" in "World")
n = Position(MyString, "e", 11)
// Returns 12 (position of "e" in "wonderful")
n = Position(MyString, "o", Length(MyString), FromEnd)
// Returns 19 (position of "o" in "World")
n = Position(MyString, "o", n-1, FromEnd)
// Returns 9 (position of "o" in "wonderful")
n = Position(MyString, "o", n-1, FromEnd)
// Returns 0 (there is no other "o")
n is int
MyString2 is string = "http://Server/File.html"
n = Position(MyString2,["/","//"])
// Returns 6
n = Position(MyString2,["/","//"], 8)
// Returns 15
Syntax

Finding a character string Hide the details

<Result> = Position(<Initial String> , <String to Find> [, <Start Position> [, <Option>]])
<Result>: Integer
  • Position of first character of character string sought in the initial string,
  • 0 if the sought string is not found.
    This position is given in relation to the beginning of string.
<Initial String>: Character string
Character string where the search will be performed (maximum size: 2 GB).
<String to Find>: Character string
Character string that must be found in the initial string.
<Start Position>: Optional integer
Subscript of character from which the search will be performed. By default, the search starts from the first character (character 1).
To perform a search from the end of the string (FromEnd constant), this parameter must correspond to 0 or to the size of the string.
If this parameter is negative, the search starts from the first character.
If this parameter is greater than the number of character found in <Initial String>, <Result> is equal to 0.
<Option>: Optional constant (or combination of constants)
Indicates the search direction and the characteristics of the search:
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 the whole word, which means enclosed in punctuation characters or in space characters
IgnoreCaseSearch while ignoring the case (uppercase/lowercase) or the accented characters
AndroidAndroid Widget iPhone/iPadApple WatchWindows Mobile

Finding an array of character strings Hide the details

<Result> = Position(<Initial String> , <Array of Strings to Find> [, <Start Position> [, <Option>]])
<Result>: Integer
  • Position of the first character in the first character string of the array found in the initial string.
    This position is given in relation to the beginning of string.
  • 0 if none of the sought strings was found.
<Initial String>: Character string
Character string where the search will be performed (maximum size: 2 GB).
<Array of Strings to Find>: Array
Array containing the character strings to find in the initial string.
<Start Position>: Optional integer
Subscript of character from which the search will be performed. By default, the search starts from the first character (character 1). To perform a search from the end of the string, this parameter must correspond to 0 or to the size of the string.
If this parameter is negative, the search starts from the first character.
If this parameter is greater than the number of character found in <Initial String>, <Result> is equal to 0.
<Option>: Optional constant (or combination of constants)
Indicates the search direction and the characteristics of the search:
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 the whole word, which means enclosed in punctuation characters or in space characters
IgnoreCaseSearch while ignoring the case (uppercase/lowercase) or the accented characters
Remarks
AndroidAndroid Widget iPhone/iPadApple WatchWindows MobileUniversal Windows 10 App

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 perform a case-insensitive search, use the IgnoreCase parameter.
The positions in a character string are always given from the beginning of the string, regardless the search direction.
To associate Position with the FromEnd constant, you must start from the position calculated by Length(<Initial String>). For example:
Position(MyString, "\", Length(MyString), FromEnd)
The following syntax can also be used. In this case, the parameter 0 allows the function to select the best start position.
Position(MyString, "\", 0, FromEnd)
AndroidAndroid Widget Windows MobileUniversal Windows 10 App

Unicode/Ansi

Position allows you to find the position of a string in a string in Unicode or Ansi format.
Strings in Ansi and/or Unicode format can be used in <Initial String> and <Sought String> (a parameter can be in Unicode format while the other one is in Ansi format).
The following conversion rule is used:
  • If at least one of the strings in in Unicode format, all the strings are converted to the Unicode format and the operation is performed in Unicode format.
  • Otherwise, the operation is performed in Ansi.
AndroidAndroid Widget iPhone/iPadApple WatchWindows MobileUniversal Windows 10 App

Characters taken into account for the punctuation and the spaces

The characters taken into account for the punctuation and the spaces are supplied by the system. To get the list of these characters, write the following WLanguage code:
s is string
FOR i = 0 TO 255
IF Charact(i) <> StringFormat(Charact(i), ccIgnorePunctuationAndSpace) THEN
 s += Charact(i)
END
END
Info(s)
ToClipboard(s)

Various

PositionOccurrence is used to find out the position of Nth occurrence of sub-string by performing a search from the beginning of string or from the end of string.
Component : wd240vm.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment