leftstr(X;Y)
Returns a string consisting of the first number of characters of a given string, or all but the last number of characters of a given string. (Available as of version 16.09)
Syntax
leftstr(X;Y)
Input
Argument | Type | Description |
---|---|---|
X |
text | The string on which to apply the function A scalar value or the name of a column |
Y |
integer | For positive values of Y , the number of characters to extract from
X , starting with the first
character. For negative values of
Y , extract all but the
last Y characters. |
Return Value
For positive values of Y
, returns a text string comprised of the first
Y
characters of X
.
For negative values of Y
, returns a text string
comprised of all but the last Y
characters
of Y
Sample Usage
value |
number |
leftstr(value;number) |
---|---|---|
'banana' | 3 | 'ban' |
'banana' | -4 | 'ba' |
'banana' | 2 | 'ba' |
'banana' | -2 | 'bana' |
Example
In the "Product Master" table (pub.demo.retail.prod), you can extract the
substrings consisting of the first three characters of the
department descriptions. To do this, create a computed column and
apply the leftstr(X;Y)
function to the
deptdesc
column.
<base table="pub.demo.retail.prod"/> <willbe name="example" value="leftstr(deptdesc;3)"/> <colord cols="deptdesc,example"/>
The results are the first three characters of the values in the deptdesc
column.
Additional Information
leftstr(X;Y)
is similar to
first(X;Y)
, with the exception that it can handle
negative Y
arguments. leftstr(X;Y)
may be
more convenient for certain applications, such as when porting code from
other languages.