Pos PowerScript function
Description
Finds one string within another string.
Syntax
1 |
<span>Pos</span> ( <span>string1</span>, <span>string2</span> {, <span>start</span> } ) |
Argument |
Description |
---|---|
string1 |
The string in which you want to find string2. |
string2 |
The string you want to find in string1. |
start |
A long indicating where the search will |
Return Values
Long. Returns a long whose value is the
starting position of the first occurrence of string2 in string1 after the
position specified in start. If string2 is
not found in string1 or if start is
not within string1, Pos returns
0. If any argument’s value is null, Pos returns null.
Usage
The Pos function is case sensitive.
Examples
This statement returns 6:
1 |
<span>Pos</span>("BABE RUTH", "RU") |
This statement returns 1:
1 |
<span>Pos</span>("BABE RUTH", "B") |
This statement returns 0, because the case does not
match:
1 |
<span>Pos</span>("BABE RUTH", "be") |
This statement starts searching at position 4 and
returns 0, because position 4 is after the occurrence of BE:
1 |
<span>Pos</span>("BABE RUTH", "BE", 4 ) |
These statements change the text NY in the SingleLineEdit sle_group to
North East:
1 |
long place_nbr |
1 |
place_nbr = <span>Pos</span>(sle_group.Text, "NY") |
1 |
sle_group.SelectText(place_nbr, 2) |
1 |
sle_group.ReplaceText("North East") |
These statements separate the return value of GetBandAtPointer into
the band name and row number. The Pos function
finds the position of the tab in the string and the Left and Mid functions
extract the information to the left and right of the tab:
1 |
string s, ls_left, ls_right |
1 |
integer li_tab |
1 |
1 |
s = dw_groups.GetBandAtPointer() |
1 |
li_tab = <span>Pos</span>(s, "~t", 1) |
1 |
1 |
ls_left = Left(s, li_tab - 1) |
1 |
ls_right = Mid(s, li_tab + 1) |
You could write similar code for a generic parsing function
with three arguments. The string s would be
an argument passed by value and ls_left and ls_right would
be strings passed by reference.
Other functions that return a pair of tab-separated values
for which you could use the parsing function are GetObjectAtPointer and GetValue.
See Also
-
GetValue method
for DataWindows in the DataWindow Reference or the online Help -
GetObjectAtPointer method
for DataWindows in the DataWindow Reference or the online Help -
Pos method for DataWindows
in the DataWindow Reference or the online Help