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:
byte 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(byte)
function.
string bits2str(
byte arg)
;
The bits2str(byte)
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.
integer 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.
string byte2base64(
byte arg)
;
The byte2base64(byte)
function takes
an array of bytes and converts it to a string in
base64
representation. Its counterpart is the
base64byte(string)
function.
string byte2hex(
byte arg)
;
The byte2hex(byte)
function takes an
array of bytes and converts it to a string in
hexadecimal
representation. Its counterpart is
the hex2byte(string)
function.
string byte2str(
byte [] payload, string charset)
;
Returns bytes converted to string
using a given charset decoder.
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 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.
integer 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 using system locale. 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 1
unlike in CTL1. Thus,
date2num(2008-06-12, month)
returns
6
. And date2num(2008-06-12,
hour)
returns 0
.
integer date2num(
date arg, unit timeunit, string locale)
;
The date2num(date, unit, string)
function accepts
three arguments: the first is date, the second is any time unit, the third is a locale.
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 using the specified locale. 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 1
unlike in CTL1. Thus,
date2num(2008-06-12, month)
returns
6
. 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 date2str(
date arg, string pattern, string locale)
;
Converts the date
field type into a date of the string
data type according to the pattern
(describing the date and time format)
and locale
(defining what date format symbols should be used). Thus,
date2str(2009/01/04,"yyyy-MMM-d","fr.CA")
returns
2009-janv.-4
. See Locale
for more info about locale settings.
number decimal2double(
decimal arg)
;
The decimal2double(decimal)
function takes one argument of decimal data
type and converts it to a double value.
The conversion is narrowing. And, if a decimal
value cannot be converted into a double
(as the ranges of double
data type do not cover all decimal
values), the function throws
exception. Thus, decimal2double(92378352147483647.23)
returns
9.2378352147483648E16
.
On the other hand, any double
can be converted into a decimal
.
Both Length and Scale of a decimal can be adjusted for it.
integer decimal2integer(
decimal arg)
;
The decimal2integer(decimal)
function takes one argument of decimal data
type and converts it to an integer.
The conversion is narrowing. And, if a decimal
value cannot be converted into an integer
(as the range of integer
data type does not cover the range of decimal
values), the function throws
exception. Thus, decimal2integer(352147483647.23)
throws
exception, whereas decimal2integer(25.95)
returns
25
.
On the other hand, any integer
can be converted into a decimal
without loss of precision. Length of a decimal can be adjusted for it.
long decimal2long(
decimal arg)
;
The decimal2long(decimal)
function takes one argument of decimal data
type and converts it to a long value.
The conversion is narrowing. And, if a decimal
value cannot be converted into a long
(as the range of long
data type does not cover all decimal
values), the function throws
exception. Thus, decimal2long(9759223372036854775807.25)
throws
exception, whereas decimal2long(72036854775807.79)
returns
72036854775807
.
On the other hand, any long
can be converted into a decimal
without loss of precision. Length of a decimal can be adjusted for it.
integer double2integer(
number arg)
;
The double2integer(number)
function takes one argument of double data
type and converts it to an integer.
The conversion is narrowing. And, if a double
value cannot be converted into an integer
(as the range of double
data type does not cover all integer
values), the function throws
exception. Thus, double2integer(352147483647.1)
throws
exception, whereas double2integer(25.757197)
returns
25
.
On the other hand, any integer
can be converted into a double
without loss of precision.
long double2long(
number arg)
;
The double2long(number)
function takes one argument of double data
type and converts it to a long.
The conversion is narrowing. And, if a double
value cannot be converted into a long
(as the range of double
data type does not cover all long
values), the function throws
exception. Thus, double2long(1.3759739E23)
throws
exception, whereas double2long(25.8579)
returns
25
.
On the other hand, any long
can always be converted into a double
,
however, user should take into account that loss of precision may occur.
string getFieldName(
record argRecord, integer index)
;
The getFieldName(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.
Important | |
---|---|
The
|
string getFieldType(
record argRecord, integer index)
;
The getFieldType(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.
Important | |
---|---|
Records as arguments look like the records for the |
byte 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(byte)
function.
string json2xml(
string arg)
;
The json2xml(string)
function takes one
string argument that is JSON
formatted
and converts it to an XML
formatted string. Its counterpart is the
xml2json(string)
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.
integer long2integer(
long arg)
;
The long2integer(decimal)
function takes one argument of long data
type and converts it to an integer value.
The conversion is successful only if it is possible
without any loss of information, otherwise the function throws
exception. Thus, long2integer(352147483647)
throws
exception, whereas long2integer(25)
returns
25
.
On the other hand, any integer
value can be converted into a long
number without loss of precision.
byte
long2packDecimal(
long arg)
;
The long2packDecimal(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 packDecimal2long(byte)
function.
byte md5(
byte arg)
;
The md5(byte)
function accepts one
argument consisting of an array of bytes. It takes this argument
and calculates its MD5
hash value.
byte 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 (integer
, long
,
number
, or decimal
) and
returns boolean false
for 0 and true
for any other value.
string num2str(
<numeric type> arg)
;
The num2str(<numeric type>)
function takes
one argument of any numeric data type (integer
, long
,
number
, or decimal
) and converts it to a string in decimal representation.
Locale is system value. Thus, num2str(20.52)
returns "20.52"
.
string num2str(
<numeric type> arg, integer radix)
;
The num2str(<numeric type>,integer)
function
accepts two arguments: the first is of any of three numeric data types (integer
, long
,
number
) 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"
. Locale is system value.
For both integer
and long
data types, any integer number can be used as radix.
For double (number
) only 10 or 16 can be used as radix.
string num2str(
<numeric type> arg, string format)
;
The num2str(<numeric type>, string)
function
accepts two arguments: the first is of any numeric data type (integer
, long
,
number
, or decimal
) and
the second is string. It takes these two arguments and converts
the first to a string in decimal representation using the format specified
as the second argument. Locale has system value.
string num2str(
<numeric type> arg, string format, string locale)
;
The num2str(<numeric type>, string, string)
function
accepts three arguments: the first is of any numeric data type (integer
, long
,
number
, or decimal
) and
two are strings. It takes these arguments and converts
the first to its string representation using the format specified
as the second argument and the locale specified as the third argument.
long packDecimal2long(
byte arg)
;
The packDecimal2long(byte)
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
long2packDecimal(long)
function.
byte sha(
byte arg)
;
The sha(byte)
function accepts one
argument consisting of an array of bytes. It takes this argument
and calculates its SHA
hash value.
byte sha(
string arg)
;
The sha(string)
function accepts one
argument of string data type. It takes this argument and
calculates its SHA
hash value.
byte str2bits(
string arg)
;
The str2bits(string)
function takes one
string argument and converts it to an array of bytes. Its
counterpart is the bits2str(byte)
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.
The first character represents the lowest bit.
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
.
string str2byte(
string payload, string charset )
;
Returns a string converted from input bytes using a given charset encoder.
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)
;
The str2date(string, string, string)
function accepts three string arguments and one
boolean. It takes the arguments and converts the first string to
the date according to the pattern
and locale
specified as
the second and the third argument, respectively. The pattern
must
correspond to the structure of the first argument. Thus,
str2date("12.6.2008", "dd.MM.yyyy",cs.CZ)
returns the
following date:
. The third argument defines the locale for the date.
2008-06-12
decimal str2decimal(
string arg)
;
The str2decimal(string)
function takes one
string argument and converts it to the corresponding decimal
value.
decimal str2decimal(
string arg, string format)
;
The str2decimal(string, string)
function takes the first
string argument and converts it to the corresponding decimal
value according to the format specified as the second argument. Locale has system value.
decimal str2decimal(
string arg, string format, string locale)
;
The str2decimal(string, string, string)
function takes the first
string argument and converts it to the corresponding decimal
value according to the format specified as the second argument and the locale specified as the third argument.
number str2double(
string arg)
;
The str2double(string)
function takes one
string argument and converts it to the corresponding double
value.
number str2double(
string arg, string format)
;
The str2double(string, string)
function takes the first
string argument and converts it to the corresponding double
value according to the format specified as the second argument. Locale has system value.
number str2double(
string arg, string format, string locale)
;
The str2decimal(string, string, string)
function takes the first
string argument and converts it to the corresponding double
value according to the format specified as the second argument and the locale specified as the third argument.
integer str2integer(
string arg)
;
The str2integer(string)
function takes one
string argument and converts it to the corresponding integer
value.
integer str2integer(
string arg, integer radix)
;
The str2integer(string, integer)
function accepts two arguments: string and integer.
It takes the first argument as if it were
expressed in the radix
based numeric system
representation and returns its corresponding integer decimal value.
integer str2integer(
string arg, string format)
;
The str2integer(string, string)
function takes the first
string argument as decimal string representation of an integer number
corresponding to the format specified as the second argument and the system locale
and converts it to the corresponding integer
value.
integer str2integer(
string arg, string format, string locale)
;
The str2integer(string, string, string)
function takes the first
string argument as decimal string representation of an integer number
corresponding to the format specified as the second argument and the locale specified as the third argument
and converts it to the corresponding integer
value.
long str2long(
string arg, integer radix)
;
The str2long(string, integer)
function accepts two arguments: string and integer.
It takes the first argument as if it were
expressed in the radix
based numeric system
representation and returns its corresponding long decimal value.
long str2long(
string arg, string format)
;
The str2long(string, string)
function takes the first
string argument as decimal string representation of a long number
corresponding to the format specified as the second argument and the system locale
and converts it to the corresponding long
value.
long str2long(
string arg, string format, string locale)
;
The str2long(string, string, string)
function takes the first
string argument as decimal string representation of a long number
corresponding to the format specified as the second argument and the locale specified as the third argument
and converts it to the corresponding long
value.
string toString(
<numeric|list|map type> arg)
;
The toString(<numeric|list|map type>)
function takes one
argument and converts it to its string
representation. It accepts any numeric data type, list of any data type, as well as map of any data types.
string xml2json(
string arg)
;
The xml2josn(string)
function takes one
string argument that is XML
formatted
and converts it to a JSON
formatted string. Its counterpart is the
json2xml(string)
function.