Beruflich Dokumente
Kultur Dokumente
Syntax:
EpochTime( cDate, cTime ) ---> Epoch Seconds
Example:
###-------------------------------------------------------------
# EpochTime()
# Example --- EpochSec = EpochTime( Date(), Time() )
# Call Format: EpochSec = EpochTime( "15/07/2016", "10:15:30" )
# EpochSec = 1468577730
#---------------------------------------------------------------
### Formula
tm_sec = Second * 1
tm_min = Minute * 60
tm_hour = Hour * 3600
tm_yday = DayOfYear * 86400
tm_year = Year - 1900
### Result
EpochSec = tm_sec + tm_min + tm_hour + tm_yday + tm_year1 + tm_year2 - tm_year3 + tm_year4
return EpochSec
THIRTY
In this chapter we are going to learn about the functions that can be used for
Checking Data Type
Checking Character
Conversion
Using the IsString() function we can know if the value is a string or not
Syntax:
IsString(value) ---> 1 if the value is a string or 0 if not
Example:
see isstring(5) + nl + # print 0
isstring("hello") + nl # print 1
Using the IsNumber() function we can know if the value is a number or not
Syntax:
186
Ring Documentation, Release 1.5
Example:
see isnumber(5) + nl + # print 1
isnumber("hello") + nl # print 0
Using the IsList() function we can know if the value is a list or not
Syntax:
IsList(value) ---> 1 if the value is a list or 0 if not
Example:
see islist(5) + nl + # print 0
islist("hello") + nl + # print 0
islist([1,3,5]) # print 1
Example:
see Type(5) + nl + # print NUMBER
Type("hello") + nl + # print STRING
Type([1,3,5]) # print LIST
We can check the value to know if its null or not using the IsNULL() function
Syntax:
IsNULL(value) ---> 1 if the value is NULL or 0 if not
Example:
see isnull(5) + nl + # print 0
isnull("hello") + nl + # print 0
isnull([1,3,5]) + nl + # print 0
isnull("") + nl + # print 1
isnull("NULL") # print 1
Example:
see isalnum("Hello") + nl + # print 1
isalnum("123456") + nl + # print 1
isalnum("ABCabc123") + nl + # print 1
isalnum("How are you") # print 0 because of spaces
Example:
see isalpha("Hello") + nl + # print 1
isalpha("123456") + nl + # print 0
isalpha("ABCabc123") + nl + # print 0
isalpha("How are you") # print 0
Example:
See iscntrl("hello") + nl + # print 0
iscntrl(nl) # print 1
Example:
see isdigit("0123456789") + nl + # print 1
isdigit("0123a") # print 0
Example:
see isgraph("abcdef") + nl + # print 1
isgraph("abc def") # print 0
Example:
see islower("abcDEF") + nl + # print 0
islower("ghi") # print 1
Example:
see isprint("Hello") + nl + # print 1
isprint("Nice to see you") + nl + # print 1
isprint(nl) # print 0
Example:
see ispunct("hello") + nl + # print 0
ispunct(",") # print 1
Example:
see isspace(" ") + nl + # print 1
isspace("test") # print 0
Example:
see isupper("welcome") + nl + # print 0
isupper("WELCOME") # print 1
Example:
see isxdigit("0123456789abcdef") + nl + # print 1
isxdigit("123z") # print 0
30.19 Conversion
We can convert strings to numbers using the Number() function or the + operator.
Syntax:
Number(string) ---> Number
0 + string ---> Number
Example:
see number("5") + 5 + nl # print 10
see 0 + "10" + 2 # print 12
We can convert numbers to strings using the String() function or the + operator.
Syntax:
String(number) ---> String
"" + number ---> String
Example:
see string(5) + 5 + nl # print 55
see "" + 10 + 2 # print 102
We can get the ASCII code for a letter using the Ascii() function
Syntax:
Ascii(character) ---> ASCII Code
Example:
See ascii("m") + nl + # print 109
ascii("M") # print 77
We can convert the ASCII code to character using the Char() function.
Syntax:
Char(ASCII Code) ---> character
Example:
See char(109) + nl + # print m
char(77) # print M
Example:
See hex(10) + nl + # print a
hex(200) # print c8
Example:
See dec("a") + nl + # print 10
dec("c8") # print 200
We can convert string characters to hexadecimal characters using the Str2hex() function.
Syntax:
Str2hex(string) ---> hexadecimal string
Example:
See str2hex("hello") # print 68656c6c6f
Example:
See hex2str("68656c6c6f") # print hello
THIRTYONE
MATHEMATICAL FUNCTIONS
The Ring programming language comes with the next mathematical functions
Function Description
sin(x) Returns the sine of an angle of x radians
cos(x) Returns the cosine of an angle of x radians
tan(x) Returns the tangent of an angle of x radians
asin(x) Returns the principal value of the arc sine of x, expressed in radians
acos(x) Returns the principal value of the arc cosine of x, expressed in radians
atan(x) Returns the principal value of the arc tangent of x, expressed in radians
atan2(y,x) Returns the principal arc tangent of y/x, in the interval [-pi,+pi] radians
sinh(x) Returns the hyperbolic sine of x radians
cosh(x) Returns the hyperbolic cosine of x radians
tanh(x) Returns the hyperbolic tangent of x radians
exp(x) Returns the value of e raised to the xth power
log(x) Returns the natural logarithm of x
log10(x) Returns the common logarithm (base-10 logarithm) of x
ceil(x) Returns the smallest integer value greater than or equal to x
floor(x) Returns the largest integer value less than or equal to x
fabs(x) Returns the absolute value of x.
pow(x,y) Returns x raised to the power of y
sqrt(x) Returns the square root of x
random(x) Returns a random number in the range [0,x]
unsigned(n,n,c) Perform operation using unsigned numbers
decimals(n) Determine the decimals digits after the point in float/double numbers
31.2 Example
See "Mathematical Functions" + nl
See "Sin(0) = " + sin(0) + nl
See "Sin(90) radians = " + sin(90) + nl
See "Sin(90) degree = " + sin(90*3.14/180) + nl
194