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.
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>])
<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.
Versions 16 and later
PHP This syntax is now available for the PHP sites.
New in version 16
PHP This syntax is now available for the PHP sites.
PHP This syntax is now available for the PHP sites.
WEBDEV - Server codeWEBDEV - Browser codePHPAjax

Finding an array of character strings Hide the details

<Result> = Position(<Initial String> , <Array of Strings to Find> [, <Start Position>])
<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.
Remarks
WEBDEV - Server codePHPAjax

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)
WEBDEV - Server codePHPAjax

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.
WEBDEV - Server codePHPAjax

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