SlideShare a Scribd company logo
CHAPTER
TWENTYSEVEN
STRINGS
In this chapter we are going to learn about strings creation and manipulation.
27.1 String Literals
Syntax:
cStr = "This is a string"
cStr2 = 'Another string'
cStr3 = :JustAnotherString
cStr4 = `Yet "another" 'string' ! `
27.2 Get String Length
We can get the string length (letters count inside a string) using the len() function
Syntax:
len(string) ---> string length
Example:
cStr = "How are you?"
see cStr + nl
see "String size : " + len(cStr) + nl
27.3 Convert Letters Case
Syntax:
lower(string) ---> convert string letters to lower case
upper(string) ---> convert string letters to UPPER case
Example:
cStr = "Welcome To The Ring Programming Language"
see cStr + nl + upper(cStr) + nl + lower(cStr)
195
Ring Documentation, Release 1.5.3
27.4 Access String Letters
We can access a letter inside a string by the letter index
Syntax:
string[index] ---> get string letter
string[index] = letter # set string letter
Example:
# print user name letter by letter (each letter in new line)
See "Hello, Enter your name : " give cName
for x = 1 to len(cName)
see nl + cName[x]
next
We can use for in to get string letters.
Example:
# print user name letter by letter (each letter in new line)
See "Hello, Enter your name : " give cName
for x in cName
see nl + x
next
We can modify the string letters
Example:
# convert the first letter to UPPER case
See "Enter your name : " give cName
cName[1] = upper(cName[1])
see "Hello " + cName
27.5 Left() Function
We can get a specified number of characters from a string using the Left() function.
The starting position is 1.
Syntax:
Left(string,count)
Example:
see left("Hello World!",5) # print Hello
27.6 Right() Function
We can get a specified number of characters from a string using the Right() function.
27.4. Access String Letters 196
Ring Documentation, Release 1.5.3
The starting position is the last character on the right.
Syntax:
Right(string,count)
Example:
see Right("Hello World!",6) # print World!
27.7 Trim() Function
We can remove all leading and trailing spaces from a string using the Trim() function.
Syntax:
trim(string)
Example:
cMsg = " Welcome "
see trim(cMsg) # print Welcome
27.8 Copy() Function
We can duplicate a string more than one time using the copy() function.
Syntax:
copy(string,nCount) ---> string replicated nCount times
Example
see copy("***hello***",3) # print ***hello******hello******hello***
27.9 Lines() Function
We can count the number of lines inside a string using the Lines() function.
Syntax:
lines(string) ---> Number of lines inside the string
Example:
cStr = "Hello
How are you?
are you fine?"
see lines(cStr) # print 3
27.7. Trim() Function 197
Ring Documentation, Release 1.5.3
27.10 Substr() Function
We can work on sub strings inside a string using the substr() function. Using Substr() we can
• Find substring
• Get substring from position to end
• Get Number of characters from position
• Transform Substring To Another Substring
27.11 Find substring
Syntax:
substr(string,substring) ---> the starting position of substring in string
Example:
cStr = "Welcome to the Ring programming language"
see substr(cStr,"Ring") # print 16
27.12 Get substring from position to end
Syntax:
substr(string,position) ---> Get substring starting from position to end
Example:
cStr = "Welcome to the Ring programming language"
nPos = substr(cStr,"Ring") # nPos = 16
see substr(cStr,nPos) # print Ring programming language
27.13 Get Number of Characters From Position
Syntax:
substr(string,position,count) ---> Get characters starting from position
Example:
cStr = "Welcome to the Ring programming language"
nPos = substr(cStr,"Ring") # nPos = 16
see substr(cStr,nPos,4) # print Ring
27.14 Transform Substring To Another Substring
Syntax:
27.10. Substr() Function 198
Ring Documentation, Release 1.5.3
substr(string,substring,newsubstring) ---> Transformed string (Match case)
substr(string,substring,newsubstring,1) ---> Transformed string (Ignore case)
Example:
cStr = "Welcome to the New programming language"
see substr(cStr,"New","Ring") + nl # print Welcome to the Ring programming language
see substr(cStr,"new","Ring",1)+ nl # print Welcome to the Ring programming language
27.15 strcmp() Function
We can compare between two strings using the strcmp() function.
Syntax:
strcmp(cString1,cString2) ---> value = 0 if cString1 = cString2
value < 0 if cString1 < cString2
value > 0 if cString1 > cString2
Example:
see strcmp("hello","hello") + nl +
strcmp("abc","bcd") + nl +
strcmp("bcd","abc") + nl
Output:
0
-1
1
27.16 str2list() and list2str() Functions
We can convert string lines to list items using the str2list() function. Also we can convert the list to a string using
list2str() function.
Syntax:
str2list(string) ---> list contains the string lines
list2str(list) ---> string contains the list items
Example:
/* output:
** Items : 4
** Item : Hello
** Item : How are you ?
** Item : are you fine ?
** Item : ok
** list2Str result = Hello
** How are you ?
** are you fine ?
** ok
** Done
*/
27.15. strcmp() Function 199
Ring Documentation, Release 1.5.3
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
27.16. str2list() and list2str() Functions 200
CHAPTER
TWENTYEIGHT
DATE AND TIME
In this chapter we are going to learn about the date and time functions.
28.1 Clock() Function
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
28.2 ClocksPerSecond() Function
Return how many clocks in one second
Syntax:
clockspersecond() ---> Number of clocks in one second
Example:
# Wait 1 second
t = clock()
while clock() - t <= clockspersecond() end
28.3 Time() Function
We can get the system time using the Time() function.
Example:
See "Time : " + time()
201
Ring Documentation, Release 1.5.3
28.4 Date() Function
We can get the date using the Date() function.
Syntax:
Date() ---> String represent the date "dd/mm/yyyy"
Example:
See "Date : " + date() # Date : 24/05/2015
28.5 TimeList() Function
We can print the date and the time information using the TimeList() function.
Syntax:
TimeList() ---> List contains the time and date information.
The next table presents the list items
index value
1 abbreviated weekday name
2 full weekday name
3 abbreviated month name
4 full month name
5 Date & Time
6 Day of the month
7 Hour (24)
8 Hour (12)
9 Day of the year
10 Month of the year
11 Minutes after hour
12 AM or PM
13 Seconds after the hour
14 Week of the year (sun-sat)
15 day of the week
16 date
17 time
18 year of the century
19 year
20 time zone
21 percent sign
Example:
/* Output:
** Sun abbreviated weekday name
** Sunday full weekday name
** May abbreviated month name
** May full month name
** 05/24/15 09:58:38 Date & Time
** 24 Day of the month
** 09 Hour (24)
28.4. Date() Function 202
Ring Documentation, Release 1.5.3
** 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
28.6 AddDays() Function
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
28.7 DiffDays() Function
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
28.6. AddDays() Function 203
Ring Documentation, Release 1.5.3
28.8 EpochTime() Function
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
#---------------------------------------------------------------
Func EpochTime(Date, Time)
arrayDate = split(Date, "/")
arrayTime = split(Time, ":")
Year = arrayDate[3] ; Month = arrayDate[2] ; Day = arrayDate[1]
Hour = arrayTime[1] ; Minute = arrayTime[2] ; Second = arrayTime[3]
cDate1 = Day +"/"+ Month +"/"+ Year
cDate2 = "01/01/" + Year
DayOfYear = DiffDays( cDate1, cDate2)
### Formula
tm_sec = Second * 1
tm_min = Minute * 60
tm_hour = Hour * 3600
tm_yday = DayOfYear * 86400
tm_year = Year - 1900
tm_year1 = ( tm_year - 70) * 31536000
tm_year2 = ( floor(( tm_year - 69) / 4 )) * 86400
tm_year3 = ( floor(( tm_year - 1) / 100 )) * 86400
tm_year4 = ( floor(( tm_year + 299) / 400 )) * 86400
### Result
EpochSec = tm_sec + tm_min + tm_hour + tm_yday + tm_year1 + tm_year2 - tm_year3 + tm_year4
return EpochSec
28.8. EpochTime() Function 204

More Related Content

PDF
The Ring programming language version 1.8 book - Part 28 of 202
PDF
The Ring programming language version 1.9 book - Part 30 of 210
PDF
The Ring programming language version 1.3 book - Part 14 of 88
PDF
The Ring programming language version 1.5.2 book - Part 22 of 181
PDF
The Ring programming language version 1.4.1 book - Part 6 of 31
PDF
The Ring programming language version 1.10 book - Part 31 of 212
PDF
The Ring programming language version 1.7 book - Part 26 of 196
PDF
The Ring programming language version 1.10 book - Part 45 of 212
The Ring programming language version 1.8 book - Part 28 of 202
The Ring programming language version 1.9 book - Part 30 of 210
The Ring programming language version 1.3 book - Part 14 of 88
The Ring programming language version 1.5.2 book - Part 22 of 181
The Ring programming language version 1.4.1 book - Part 6 of 31
The Ring programming language version 1.10 book - Part 31 of 212
The Ring programming language version 1.7 book - Part 26 of 196
The Ring programming language version 1.10 book - Part 45 of 212

What's hot (20)

PDF
Mysqlfunctions
PDF
Creating a Custom Serialization Format (Gophercon 2017)
PPTX
heapsort_bydinesh
PPTX
Computer programming 2 Lesson 14
PDF
The Ring programming language version 1.4.1 book - Part 7 of 31
PPTX
Pemrograman Terstruktur 4
PDF
Rust Synchronization Primitives
PPT
MySQL Functions
PPTX
Date and time functions in mysql
PPTX
DOCX
CLUSTERGRAM
ODP
PDF
The Ring programming language version 1.10 book - Part 127 of 212
PDF
The Ring programming language version 1.5.4 book - Part 12 of 185
PDF
The Ring programming language version 1.9 book - Part 33 of 210
PPT
MySQL Built-In Functions
 
PDF
The Ring programming language version 1.10 book - Part 28 of 212
PDF
Taming Asynchronous Transforms with Interstellar
PDF
The Ring programming language version 1.5.2 book - Part 34 of 181
Mysqlfunctions
Creating a Custom Serialization Format (Gophercon 2017)
heapsort_bydinesh
Computer programming 2 Lesson 14
The Ring programming language version 1.4.1 book - Part 7 of 31
Pemrograman Terstruktur 4
Rust Synchronization Primitives
MySQL Functions
Date and time functions in mysql
CLUSTERGRAM
The Ring programming language version 1.10 book - Part 127 of 212
The Ring programming language version 1.5.4 book - Part 12 of 185
The Ring programming language version 1.9 book - Part 33 of 210
MySQL Built-In Functions
 
The Ring programming language version 1.10 book - Part 28 of 212
Taming Asynchronous Transforms with Interstellar
The Ring programming language version 1.5.2 book - Part 34 of 181
Ad

Similar to The Ring programming language version 1.5.3 book - Part 23 of 184 (20)

PDF
The Ring programming language version 1.6 book - Part 25 of 189
PDF
The Ring programming language version 1.5.4 book - Part 23 of 185
PDF
The Ring programming language version 1.2 book - Part 13 of 84
PDF
The Ring programming language version 1.4 book - Part 6 of 30
PDF
The Ring programming language version 1.5.1 book - Part 21 of 180
PDF
The Ring programming language version 1.5.1 book - Part 22 of 180
PDF
The Ring programming language version 1.5.2 book - Part 23 of 181
PDF
The Ring programming language version 1.10 book - Part 32 of 212
PDF
The Ring programming language version 1.7 book - Part 27 of 196
PDF
The Ring programming language version 1.3 book - Part 15 of 88
PDF
The Ring programming language version 1.5.4 book - Part 24 of 185
PDF
The Ring programming language version 1.5.4 book - Part 35 of 185
PDF
The Ring programming language version 1.9 book - Part 31 of 210
PDF
The Ring programming language version 1.5.3 book - Part 35 of 184
PDF
The Ring programming language version 1.3 book - Part 26 of 88
PDF
The Ring programming language version 1.6 book - Part 37 of 189
PDF
The Ring programming language version 1.8 book - Part 29 of 202
PDF
The Ring programming language version 1.2 book - Part 24 of 84
PDF
The Ring programming language version 1.8 book - Part 40 of 202
PDF
The Ring programming language version 1.9 book - Part 42 of 210
The Ring programming language version 1.6 book - Part 25 of 189
The Ring programming language version 1.5.4 book - Part 23 of 185
The Ring programming language version 1.2 book - Part 13 of 84
The Ring programming language version 1.4 book - Part 6 of 30
The Ring programming language version 1.5.1 book - Part 21 of 180
The Ring programming language version 1.5.1 book - Part 22 of 180
The Ring programming language version 1.5.2 book - Part 23 of 181
The Ring programming language version 1.10 book - Part 32 of 212
The Ring programming language version 1.7 book - Part 27 of 196
The Ring programming language version 1.3 book - Part 15 of 88
The Ring programming language version 1.5.4 book - Part 24 of 185
The Ring programming language version 1.5.4 book - Part 35 of 185
The Ring programming language version 1.9 book - Part 31 of 210
The Ring programming language version 1.5.3 book - Part 35 of 184
The Ring programming language version 1.3 book - Part 26 of 88
The Ring programming language version 1.6 book - Part 37 of 189
The Ring programming language version 1.8 book - Part 29 of 202
The Ring programming language version 1.2 book - Part 24 of 84
The Ring programming language version 1.8 book - Part 40 of 202
The Ring programming language version 1.9 book - Part 42 of 210
Ad

More from Mahmoud Samir Fayed (20)

PDF
The Ring programming language version 1.10 book - Part 212 of 212
PDF
The Ring programming language version 1.10 book - Part 211 of 212
PDF
The Ring programming language version 1.10 book - Part 210 of 212
PDF
The Ring programming language version 1.10 book - Part 208 of 212
PDF
The Ring programming language version 1.10 book - Part 207 of 212
PDF
The Ring programming language version 1.10 book - Part 205 of 212
PDF
The Ring programming language version 1.10 book - Part 206 of 212
PDF
The Ring programming language version 1.10 book - Part 204 of 212
PDF
The Ring programming language version 1.10 book - Part 203 of 212
PDF
The Ring programming language version 1.10 book - Part 202 of 212
PDF
The Ring programming language version 1.10 book - Part 201 of 212
PDF
The Ring programming language version 1.10 book - Part 200 of 212
PDF
The Ring programming language version 1.10 book - Part 199 of 212
PDF
The Ring programming language version 1.10 book - Part 198 of 212
PDF
The Ring programming language version 1.10 book - Part 197 of 212
PDF
The Ring programming language version 1.10 book - Part 196 of 212
PDF
The Ring programming language version 1.10 book - Part 195 of 212
PDF
The Ring programming language version 1.10 book - Part 194 of 212
PDF
The Ring programming language version 1.10 book - Part 193 of 212
PDF
The Ring programming language version 1.10 book - Part 192 of 212
The Ring programming language version 1.10 book - Part 212 of 212
The Ring programming language version 1.10 book - Part 211 of 212
The Ring programming language version 1.10 book - Part 210 of 212
The Ring programming language version 1.10 book - Part 208 of 212
The Ring programming language version 1.10 book - Part 207 of 212
The Ring programming language version 1.10 book - Part 205 of 212
The Ring programming language version 1.10 book - Part 206 of 212
The Ring programming language version 1.10 book - Part 204 of 212
The Ring programming language version 1.10 book - Part 203 of 212
The Ring programming language version 1.10 book - Part 202 of 212
The Ring programming language version 1.10 book - Part 201 of 212
The Ring programming language version 1.10 book - Part 200 of 212
The Ring programming language version 1.10 book - Part 199 of 212
The Ring programming language version 1.10 book - Part 198 of 212
The Ring programming language version 1.10 book - Part 197 of 212
The Ring programming language version 1.10 book - Part 196 of 212
The Ring programming language version 1.10 book - Part 195 of 212
The Ring programming language version 1.10 book - Part 194 of 212
The Ring programming language version 1.10 book - Part 193 of 212
The Ring programming language version 1.10 book - Part 192 of 212

Recently uploaded (20)

PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Cloud computing and distributed systems.
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
KodekX | Application Modernization Development
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Electronic commerce courselecture one. Pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
20250228 LYD VKU AI Blended-Learning.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Big Data Technologies - Introduction.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
The AUB Centre for AI in Media Proposal.docx
Understanding_Digital_Forensics_Presentation.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Cloud computing and distributed systems.
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
MYSQL Presentation for SQL database connectivity
Diabetes mellitus diagnosis method based random forest with bat algorithm
Review of recent advances in non-invasive hemoglobin estimation
KodekX | Application Modernization Development
MIND Revenue Release Quarter 2 2025 Press Release
Electronic commerce courselecture one. Pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?

The Ring programming language version 1.5.3 book - Part 23 of 184

  • 1. CHAPTER TWENTYSEVEN STRINGS In this chapter we are going to learn about strings creation and manipulation. 27.1 String Literals Syntax: cStr = "This is a string" cStr2 = 'Another string' cStr3 = :JustAnotherString cStr4 = `Yet "another" 'string' ! ` 27.2 Get String Length We can get the string length (letters count inside a string) using the len() function Syntax: len(string) ---> string length Example: cStr = "How are you?" see cStr + nl see "String size : " + len(cStr) + nl 27.3 Convert Letters Case Syntax: lower(string) ---> convert string letters to lower case upper(string) ---> convert string letters to UPPER case Example: cStr = "Welcome To The Ring Programming Language" see cStr + nl + upper(cStr) + nl + lower(cStr) 195
  • 2. Ring Documentation, Release 1.5.3 27.4 Access String Letters We can access a letter inside a string by the letter index Syntax: string[index] ---> get string letter string[index] = letter # set string letter Example: # print user name letter by letter (each letter in new line) See "Hello, Enter your name : " give cName for x = 1 to len(cName) see nl + cName[x] next We can use for in to get string letters. Example: # print user name letter by letter (each letter in new line) See "Hello, Enter your name : " give cName for x in cName see nl + x next We can modify the string letters Example: # convert the first letter to UPPER case See "Enter your name : " give cName cName[1] = upper(cName[1]) see "Hello " + cName 27.5 Left() Function We can get a specified number of characters from a string using the Left() function. The starting position is 1. Syntax: Left(string,count) Example: see left("Hello World!",5) # print Hello 27.6 Right() Function We can get a specified number of characters from a string using the Right() function. 27.4. Access String Letters 196
  • 3. Ring Documentation, Release 1.5.3 The starting position is the last character on the right. Syntax: Right(string,count) Example: see Right("Hello World!",6) # print World! 27.7 Trim() Function We can remove all leading and trailing spaces from a string using the Trim() function. Syntax: trim(string) Example: cMsg = " Welcome " see trim(cMsg) # print Welcome 27.8 Copy() Function We can duplicate a string more than one time using the copy() function. Syntax: copy(string,nCount) ---> string replicated nCount times Example see copy("***hello***",3) # print ***hello******hello******hello*** 27.9 Lines() Function We can count the number of lines inside a string using the Lines() function. Syntax: lines(string) ---> Number of lines inside the string Example: cStr = "Hello How are you? are you fine?" see lines(cStr) # print 3 27.7. Trim() Function 197
  • 4. Ring Documentation, Release 1.5.3 27.10 Substr() Function We can work on sub strings inside a string using the substr() function. Using Substr() we can • Find substring • Get substring from position to end • Get Number of characters from position • Transform Substring To Another Substring 27.11 Find substring Syntax: substr(string,substring) ---> the starting position of substring in string Example: cStr = "Welcome to the Ring programming language" see substr(cStr,"Ring") # print 16 27.12 Get substring from position to end Syntax: substr(string,position) ---> Get substring starting from position to end Example: cStr = "Welcome to the Ring programming language" nPos = substr(cStr,"Ring") # nPos = 16 see substr(cStr,nPos) # print Ring programming language 27.13 Get Number of Characters From Position Syntax: substr(string,position,count) ---> Get characters starting from position Example: cStr = "Welcome to the Ring programming language" nPos = substr(cStr,"Ring") # nPos = 16 see substr(cStr,nPos,4) # print Ring 27.14 Transform Substring To Another Substring Syntax: 27.10. Substr() Function 198
  • 5. Ring Documentation, Release 1.5.3 substr(string,substring,newsubstring) ---> Transformed string (Match case) substr(string,substring,newsubstring,1) ---> Transformed string (Ignore case) Example: cStr = "Welcome to the New programming language" see substr(cStr,"New","Ring") + nl # print Welcome to the Ring programming language see substr(cStr,"new","Ring",1)+ nl # print Welcome to the Ring programming language 27.15 strcmp() Function We can compare between two strings using the strcmp() function. Syntax: strcmp(cString1,cString2) ---> value = 0 if cString1 = cString2 value < 0 if cString1 < cString2 value > 0 if cString1 > cString2 Example: see strcmp("hello","hello") + nl + strcmp("abc","bcd") + nl + strcmp("bcd","abc") + nl Output: 0 -1 1 27.16 str2list() and list2str() Functions We can convert string lines to list items using the str2list() function. Also we can convert the list to a string using list2str() function. Syntax: str2list(string) ---> list contains the string lines list2str(list) ---> string contains the list items Example: /* output: ** Items : 4 ** Item : Hello ** Item : How are you ? ** Item : are you fine ? ** Item : ok ** list2Str result = Hello ** How are you ? ** are you fine ? ** ok ** Done */ 27.15. strcmp() Function 199
  • 6. Ring Documentation, Release 1.5.3 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 27.16. str2list() and list2str() Functions 200
  • 7. CHAPTER TWENTYEIGHT DATE AND TIME In this chapter we are going to learn about the date and time functions. 28.1 Clock() Function 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 28.2 ClocksPerSecond() Function Return how many clocks in one second Syntax: clockspersecond() ---> Number of clocks in one second Example: # Wait 1 second t = clock() while clock() - t <= clockspersecond() end 28.3 Time() Function We can get the system time using the Time() function. Example: See "Time : " + time() 201
  • 8. Ring Documentation, Release 1.5.3 28.4 Date() Function We can get the date using the Date() function. Syntax: Date() ---> String represent the date "dd/mm/yyyy" Example: See "Date : " + date() # Date : 24/05/2015 28.5 TimeList() Function We can print the date and the time information using the TimeList() function. Syntax: TimeList() ---> List contains the time and date information. The next table presents the list items index value 1 abbreviated weekday name 2 full weekday name 3 abbreviated month name 4 full month name 5 Date & Time 6 Day of the month 7 Hour (24) 8 Hour (12) 9 Day of the year 10 Month of the year 11 Minutes after hour 12 AM or PM 13 Seconds after the hour 14 Week of the year (sun-sat) 15 day of the week 16 date 17 time 18 year of the century 19 year 20 time zone 21 percent sign Example: /* Output: ** Sun abbreviated weekday name ** Sunday full weekday name ** May abbreviated month name ** May full month name ** 05/24/15 09:58:38 Date & Time ** 24 Day of the month ** 09 Hour (24) 28.4. Date() Function 202
  • 9. Ring Documentation, Release 1.5.3 ** 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 28.6 AddDays() Function 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 28.7 DiffDays() Function 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 28.6. AddDays() Function 203
  • 10. Ring Documentation, Release 1.5.3 28.8 EpochTime() Function 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 #--------------------------------------------------------------- Func EpochTime(Date, Time) arrayDate = split(Date, "/") arrayTime = split(Time, ":") Year = arrayDate[3] ; Month = arrayDate[2] ; Day = arrayDate[1] Hour = arrayTime[1] ; Minute = arrayTime[2] ; Second = arrayTime[3] cDate1 = Day +"/"+ Month +"/"+ Year cDate2 = "01/01/" + Year DayOfYear = DiffDays( cDate1, cDate2) ### Formula tm_sec = Second * 1 tm_min = Minute * 60 tm_hour = Hour * 3600 tm_yday = DayOfYear * 86400 tm_year = Year - 1900 tm_year1 = ( tm_year - 70) * 31536000 tm_year2 = ( floor(( tm_year - 69) / 4 )) * 86400 tm_year3 = ( floor(( tm_year - 1) / 100 )) * 86400 tm_year4 = ( floor(( tm_year + 299) / 400 )) * 86400 ### Result EpochSec = tm_sec + tm_min + tm_hour + tm_yday + tm_year1 + tm_year2 - tm_year3 + tm_year4 return EpochSec 28.8. EpochTime() Function 204