Sometimes you need to convert values from one data type to another.
In the functions that convert one data type to another, sometimes a format pattern of a date or any number must be defined. Also locale can have an influence to their formatting.
For detailed information about date formatting and/or parsing see Data and Time Format.
For detailed information about formatting and/or parsing of any numeric data type see Numeric Format.
For detailed information about locale see Locale.
Note | |
---|---|
Remember that numeric and date formats are displayed using system
value Locale or Locale specified in the For more information on how Locale may be changed in the |
Here we provide the list of these functions:
bytearray base64byte(
string arg)
;
The base64byte(string)
function takes one
string argument in base64
representation and
converts it to an array of bytes. Its counterpart is the
byte2base64(bytearray)
function.
string bits2str(
bytearray arg)
;
The bits2str(bytearray)
function takes an
array of bytes and converts it to a string consisting of two
characters: "0"
or "1"
. Each
byte is represented by eight characters ("0" or "1"). For each
byte, the lowest bit is at the beginning of these eight
characters. The counterpart is the
str2bits(string)
function.
int bool2num(
boolean arg)
;
The bool2num(boolean)
function takes one
boolean argument and converts it to either integer
(if the argument is true)
or integer 1
(if the
argument is false). Its counterpart is the
0
num2bool(<numeric type>)
function.
<numeric type> bool2num(
boolean arg, typename
<numeric type>)
;
The bool2num(boolean, typename)
function
accepts two arguments: the first is boolean and the other is the
name of any numeric data type. It takes them and converts the
first argument to the corresponding 1
or
in the
0
numeric
representation specified by the second
argument. The return type of the function is the same as the
second argument. Its counterpart is the
num2bool(<numeric type>)
function.
string byte2base64(
bytearray arg)
;
The byte2base64(bytearray)
function takes
an array of bytes and converts it to a string in
base64
representation. Its counterpart is the
base64byte(string)
function.
string byte2hex(
bytearray arg)
;
The byte2hex(bytearray)
function takes an
array of bytes and converts it to a string in
hexadecimal
representation. Its counterpart is
the hex2byte(string)
function.
long date2long(
date arg)
;
The date2long(date)
function takes one
date argument and converts it to a long type. Its value is equal
to the the number of milliseconds elapsed from January 1,
1970, 00:00:00 GMT
to the date specified as the
argument. Its counterpart is the
long2date(long)
function.
int date2num(
date arg, unit timeunit)
;
The date2num(date, unit)
function accepts
two arguments: the first is date and the other is any time unit.
The unit can be one of the following: year
,
month
, week
,
day
, hour
,
minute
, second
,
millisec
. The unit must be specified as a
constant. It can neither be received through an edge nor set as
variable. The function takes these two arguments and converts them
to an integer. If the time unit is contained in the date, it is
returned as an integer number. If it is not contained, the
function returns 0
. Remember that months are
numbered starting from 0
. Thus,
date2num(2008-06-12, month)
returns
5
. And date2num(2008-06-12,
hour)
returns 0
.
string date2str(
date arg, string pattern)
;
The date2str(date, string)
function
accepts two arguments: date and string. The function takes them
and converts the date according to the pattern
specified as the second argument. Thus,
date2str(2008-06-12, "dd.MM.yyyy")
returns the
following string:
. Its counterpart
is the "12.6.2008
"str2date(string, string)
function.
string get_field_name(
record argRecord, integer index)
;
The get_field_name(record, integer)
function accepts two arguments: record and integer. The function
takes them and returns the name of the field with the specified
index. Fields are numbered starting from 0.
string get_field_type(
record argRecord, integer index)
;
The get_field_type(record, integer)
function accepts two arguments: record and integer. The function
takes them and returns the type of the field with the specified
index. Fields are numbered starting from 0.
bytearray hex2byte(
string arg)
;
The hex2byte(string)
function takes one
string argument in hexadecimal
representation
and converts it to an array of bytes. Its counterpart is the
byte2hex(bytearray)
function.
date long2date(
long arg)
;
The long2date(long)
function takes one
long argument and converts it to a date. It adds the argument
number of milliseconds to January 1, 1970, 00:00:00
GMT
and returns the result as a date. Its counterpart is
the date2long(date)
function.
bytearray
long2pacdecimal(
long arg)
;
The long2pacdecimal(long)
function takes
one argument of long data type and returns its value in the
representation of packed decimal number. It is the counterpart of
the pacdecimal2long(bytearray)
function.
bytearray md5(
bytearray arg)
;
The md5(bytearray)
function accepts one
argument consisting of an array of bytes. It takes this argument
and calculates its MD5
hash value.
bytearray md5(
string arg)
;
The md5(string)
function accepts one
argument of string data type. It takes this argument and
calculates its MD5
hash value.
boolean num2bool(
<numeric type> arg)
;
The num2bool(<numeric type>)
function takes
one argument of any numeric data type representing 1 or 0 and
returns boolean true
or
false
, respectively.
<numeric type> num2num(
<numeric type> arg, typename
<numeric type>)
;
The num2num(<numeric type>, typename)
function accepts two arguments: the first is of any numeric data
type and the second is the name of any numeric data type. It takes
them and converts the first argument value to that of the
numeric
type specified as the second argument.
The return type of the function is the same as the second
argument. The conversion is successful only if it is possible
without any loss of information, otherwise the function throws
exception. Thus, num2num(25.4, int)
throws
exception, whereas num2num(25.0, int)
returns
25
.
string num2str(
<numeric type> arg)
;
The num2str(<numeric type>)
function takes
one argument of any numeric data type and converts it to its
string representation. Thus, num2str(20.52)
returns "20.52"
.
string num2str(
<numeric type> arg, int radix)
;
The num2str(<numeric type>, int)
function
accepts two arguments: the first is of any numeric data type and
the second is integer. It takes these two arguments and converts
the first to its string representation in the
radix
based numeric system. Thus,
num2str(31, 16)
returns
"1F"
.
string num2str(
<numeric type> arg, string format)
;
The num2str(<numeric type>, string)
function
accepts two arguments: the first is of any numeric data type and
the second is string. It takes these two arguments and converts
the first to its string representation using the format specified
as the second argument.
long pacdecimal2long(
bytearray arg)
;
The pacdecimal2long(bytearray)
function
takes one argument of an array of bytes whose meaning is the
packed decimal representation of a long number. It returns its
value as long data type. It is the counterpart of the
long2pacdecimal(long)
function.
bytearray sha(
bytearray arg)
;
The sha(bytearray)
function accepts one
argument consisting of an array of bytes. It takes this argument
and calculates its SHA
hash value.
bytearray sha(
string arg)
;
The sha(string)
function accepts one
argument of string data type. It takes this argument and
calculates its SHA
hash value.
bytearray str2bits(
string arg)
;
The str2bits(string)
function takes one
string argument and converts it to an array of bytes. Its
counterpart is the bits2str(bytearray)
function. The string consists of the following characters: Each of
them can be either "1"
or it can be any other
character. In the string, each character "1"
is
converted to the bit 1
, all other characters
(not only "0"
, but also "a"
,
"z"
, "/"
, etc.) are
converted to the bit 0
. If the number of
characters in the string is not an integral multiple of eight, the
string is completed by "0" characters from the right. Then, the
string is converted to an array of bytes as if the number of its
characters were integral multiple of eight.
boolean str2bool(
string arg)
;
The str2bool(string)
function takes one
string argument and converts it to the corresponding boolean
value. The string can be one of the following:
"TRUE"
, "true"
,
"T"
, "t"
,
"YES"
, "yes"
,
"Y"
, "y"
,
"1"
, "FALSE"
,
"false"
, "F"
,
"f"
, "NO"
,
"no"
, "N"
,
"n"
, "0"
. The strings are
converted to boolean true
or boolean
false
.
date str2date(
string arg, string pattern)
;
The str2date(string, string)
function
accepts two string arguments. It takes them and converts the first
string to the date according to the pattern
specified as the second argument. The pattern
must correspond to the structure of the first argument. Thus,
str2date("12.6.2008", "dd.MM.yyyy")
returns the
following date: 2008-06-12
.
date str2date(
string arg, string pattern, string locale, boolean lenient)
;
The str2date(string, string, string,
boolean)
function accepts three string arguments and one
boolean. It takes the arguments and converts the first string to
the date according to the pattern
specified as
the second argument. The pattern
must
correspond to the structure of the first argument. Thus,
str2date("12.6.2008", "dd.MM.yyyy")
returns the
following date:
. The third argument defines the locale for the date.
The fourth argument specify whether date interpretation should be
lenient (true) or not (false). If it is true, the function tries
to make interpretation of the date even if it does not match
locale and/or pattern. If this function has three arguments only,
the third one is interpreted as locale (if it is string) or
lenient (if it is boolean).2008-06-12
<numeric type> str2num(
string arg)
;
The str2num(string)
function takes one
string argument and converts it to the corresponding numeric
value. Thus, str2num("0.25")
returns
0.25
if the function is declared with double
return type, but the same throws exception if it is declared with
integer return type. The return type of the function can be any
numeric type.
<numeric type> str2num(
string arg, typename
<numeric type>)
;
The str2num(string, typename)
function
accepts two arguments: the first is string and the second is the
name of any numeric data type. It takes the first argument and
returns its corresponding value in the numeric
data type specified by the second argument. The return type of the
function is the same as the second argument.
<numeric type> str2num(
string arg, typename
<numeric type>, int radix)
;
The str2num(string, typename, int)
function accepts three arguments: string, the name of any numeric
data type and integer. It takes the first argument as if it were
expressed in the radix
based numeric system
representation and returns its corresponding value in the
numeric
data type specified as the second
argument. The return type is the same as the second argument. The
third argument can be 10
or
16
for number
data type as
the second argument (however, radix does not need to be specified
as the form of the string alone determines whether the string is
decimal or hexadecimal string representation of a number),
10
for decimal
type as the
second argument and any integer number between
Character.MIN_RADIX
and
Character.MAX_RADIX
for int
and long
types as the second argument.
<numeric type> str2num(
string arg, typename
<numeric type>, string format)
;
The str2num(string, typename, string)
function accepts three arguments. The first is a string that
should be converted to the number, the second is the name of the
return numeric data type and the third is the format of the string
representation of a number used in the first argument. The type
name specified as the second argument can neither be received
through the edge nor be defined as variable. It must be specified
directly in the function. The function takes the first argument,
compares it with the format using system value locale and returns
the numeric value of data type specified as the second
argument.
<numeric type> str2num(
string arg, typename
<numeric type>, string format, string locale)
;
The str2num(string, typename, string,
string)
function accepts four arguments. The first is a
string that should be converted to the number, the second is the
name of the return numeric data type, the third is the format of
the string representation of a number used in the first argument
and the fourth is the locale that should be used when applying the
format. The type name specified as the second argument can neither
be received through the edge nor be defined as variable. It must
be specified directly in the function. The function takes the
first argument, compares it with the format using the locale at
the same time and returns the numeric value of data type specified
as the second argument.
string to_string(
<any type> arg)
;
The to_string
(<any type>)
function takes one
argument of any data type and converts it to its string
representation.
returndatatype
try_convert(
<any type> from, typename
returndatatype)
;
The try_convert(<any type>, typename)
function accepts two arguments: the first is of any data type and
the second is the name of any other data type. The name of the
second argument can neither be received through the edge nor be
defined as variable. It must be specified directly in the
function. The function takes these arguments and tries to convert
the first argument to specified data type. If the conversion is
possible, the function converts the first argument to data type
specified as the second argument. If the conversion is not
possible, the function returns null.
date try_convert(
string from, datetypename date, string format)
;
The try_convert(string, nameofdatedatatype,
string)
function accepts three arguments: the first is
of string data type, the second is the name of date data type and
the third is a format of the first argument. The
date
word specified as the second argument can
neither be received through the edge nor be defined as variable.
It must be specified directly in the function. The function takes
these arguments and tries to convert the first argument to a date.
If the string specified as the first argument corresponds to the
form of the third argument, conversion is possible and a date is
returned. If the conversion is not possible, the function returns
null.
string try_convert(
date from, stringtypename
string, string format)
;
The try_convert(date, nameofstringdatatype,
string)
function accepts three arguments: the first is
of date data type, the second is the name of string data type and
the third is a format of a string representation of a date. The
string word specified as the second argument can neither be
received through the edge nor be defined as variable. It must be
specified directly in the function. The function takes these
arguments and converts the first argument to a string in the form
specified by the third argument.
boolean try_convert(
<any type> from, <any type> to, string pattern)
;
The try_convert(<any type>, <any type>, string)
function accepts three arguments: two are of any data type, the
third is string. The function takes these arguments, tries convert
the first argument to the second. If the conversion is successful,
the second argument receives the value from the first argument.
And the function returns boolean true. If the conversion is not
successful, the function returns boolean false and the first and
second arguments retain their original values. The third argument
is optional and it is used only if any of the first two arguments
is string. For example, try_convert("27.5.1942", dateA,
"dd.MM.yyyy")
returns true
and
dateA
gets the value of the 27 May 1942.