Professional Documents
Culture Documents
mystr = "Hello
How are you ?
are you fine ?
ok"
mylist = str2list(mystr)
see "Items : " + len(mylist) + nl
for x in mylist
see "Item : " + x + nl
next
newstr = list2str(mylist)
see "list2Str result = " + newstr
if mystr = newstr
see nl + "Done"
else
see nl + "Error!"
ok
TWENTYEIGHT
In this chapter we are going to learn about the date and time functions.
Syntax:
Clock() ---> The number of clock ticks from program start
Example:
See "Calculate performance" + nl
t1 = clock()
for x = 1 to 1000000 next
see clock() - t1
Example:
# Wait 1 second
t = clock()
while clock() - t <= clockspersecond() end
186
Ring Documentation, Release 1.5.1
Example:
See "Date : " + date() # Date : 24/05/2015
We can print the date and the time information using the TimeList() function.
Syntax:
TimeList() ---> List contains the time and date information.
** 09 Hour (12)
** 144 Day of the year
** 05 Month of the year
** 58 Minutes after hour
** AM AM or PM
** 38 Seconds after the hour
** 21 Week of the year (sun-sat)
** 0 day of the week
** 05/24/15 date
** 09:58:38 time
** 15 year of the century
** 2015 year
** Arab Standard Time time zone
** % percent sign
*/
See TimeList()
Example:
See "Day Name : " + TimeList()[2] # Sunday
Example:
See "Month Name : " + TimeList()[4] # May
Syntax:
AddDays(cDate,nDays) ---> Date from cDate and after nDays
Example:
cDate = date()
see cDate + nl # 24/05/2015
cDate = adddays(cDate,10)
see cDate + nl # 03/06/2015
Syntax:
DiffDays(cDate1,cDate2) ---> number of days (Date1 - Date2)
Example:
cDate1 = date()
see cDate1 + nl # 24/05/2015
cDate2 = adddays(cDate1,10)
see cDate2 + nl # 03/06/2015
see "DiffDays = " + diffdays(cDate1,cDate2) + nl # -10
see "DiffDays = " + diffdays(cDate2,cDate1) + nl # 10
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
TWENTYNINE
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:
190
Ring Documentation, Release 1.5.1
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