SlideShare a Scribd company logo
Ring Documentation, Release 1.2
Example:
aList = ["one","two"]
add(aList,"three")
see aList
Also we can do that using the + operator.
Syntax:
List + item
Example:
aList = 1:10 # create list contains numbers from 1 to 10
aList + 11 # add number 11 to the list
see aList # print the list
21.3 Get List Size
We can get the list size using the len() function
Syntax:
Len(List)
Example:
aList = 1:20 see len(aList) # print 20
21.4 Delete Item From List
To delete an item from the list, we can use the del() function
Syntax:
del(list,index)
Example:
aList = ["one","two","other","three"]
Del(aList,3) # delete item number three
see aList # print one two three
21.5 Get List Item
To get an item from the list, we uses the next syntax
List[Index]
Example:
aList = ["Cairo","Riyadh"]
see "Egypt : " + aList[1] + nl +
"KSA : " + aList[2] + nl
21.3. Get List Size 90
Ring Documentation, Release 1.2
21.6 Set List Item
To set the value of an item inside the list, we can use the next syntax
List[Index] = Expression
Example:
aList = list(3) # create list contains three items
aList[1] = "one" aList[2] = "two" aList[3] = "three"
see aList
21.7 Search
To find an item inside the list we can use the find() function
Syntax:
Find(List,ItemValue) ---> Item Index
Find(List,ItemValue,nColumn) ---> Search in nColumn, returns the Item Index
Find(List,ItemValue,nColumn,cAttribute) ---> Item Index
Example:
aList = ["one","two","three","four","five"]
see find(aList,"three") # print 3
Example:
mylist = [["one",1],
["two",2],
["three",3]]
see find(mylist,"two",1) + nl # print 2
see find(mylist,2,2) + nl # print 2
Also we can use the binarysearch() function to search in sorted list.
Syntax:
BinarySearch(List,ItemValue) ---> Item Index
BinarySearch(List,ItemValue,nColumn) ---> Search in nColumn, returns the Item Index
Example:
aList = ["one","two","three","four","five"]
aList = sort(aList)
see binarysearch(aList,"three")
Output:
five
four
one
three
two
4
21.6. Set List Item 91
Ring Documentation, Release 1.2
21.8 Sort
We can sort the list using the sort() function.
Syntax:
Sort(List) ---> Sorted List
Sort(List,nColumn) ---> Sorted List based on nColumn
Sort(List,nColumn,cAttribute) ---> Sorted List based on Object Attribute
Example:
aList = [10,12,3,5,31,15]
aList = sort(aList) see aList # print 3 5 10 12 15 31
We can sort list of strings
Example:
mylist = ["mahmoud","samir","ahmed","ibrahim","mohammed"]
see mylist # print list before sorting
mylist = sort(mylist) # sort list
see "list after sort"+nl
see mylist # print ahmed ibrahim mahmoud mohammed samir
We can sort a list based on a specific column.
Example:
aList = [ ["mahmoud",15000] ,
["ahmed", 14000 ] ,
["samir", 16000 ] ,
["mohammed", 12000 ] ,
["ibrahim",11000 ] ]
aList2 = sort(aList,1)
see aList2
Output:
ahmed
14000
ibrahim
11000
mahmoud
15000
mohammed
12000
samir
16000
21.9 Reverse
We can reverse a list using the reverse() function.
Syntax:
21.8. Sort 92
Ring Documentation, Release 1.2
Reverse(List) ---> Reversed List
Example:
aList = [10,20,30,40,50]
aList = reverse(aList)
see aList # print 50 40 30 20 10
21.10 Insert Items
To insert an item in the list we can use the insert() function.
Syntax:
Insert(List,Index,Item)
The inserted item will be AFTER the Index
Example:
aList = ["A","B","D","E"]
insert(aList,2,"C") # Inserts AFTER Index 2, "C" into Position 3
see aList # print A B C D E
21.11 Nested Lists
The list may contain other lists
Example:
aList = [ 1 , [10,20,30] , 5 , [100,1000,5000] ]
aList2 = [
"one","two",
[3,4],
[20,30], ["three",
"four",
"five",[100,200,300]
]
]
see aList[2] # print 10 20 30
see aList[4][3] + nl # print 5000
see aList2[5][2] + nl # print four
see aList2[5][4][3] # print 300
21.12 Copy Lists
We can copy lists (including nested lists) using the Assignment operator.
Example:
21.10. Insert Items 93
Ring Documentation, Release 1.2
aList = [
"one","two",
[3,4],
[20,30], ["three",
"four",
"five",[100,200,300]
]
]
aList2 = aList # Copy aList to aList2
aList2[5] = "other" # modify item number five
see aList2[5] + nl # print other
see aList[5] # print three four five 100 200 300
21.13 First-class lists
Lists are first-class citizens where we can store lists in variables, pass lists to functions, and return lists from functions.
Example:
aList = duplicate( [1,2,3,4,5] )
see aList[10] + nl # print 5
see mylist() # print 10 20 30 40 50
func duplicate list
nMax = len(list)
for x = 1 to nMax
list + list[x]
next
return list
func mylist return [10,20,30,40,50]
21.14 Using Lists during definition
We can use the list items while we are defining the list for the first time.
Example:
aList = [ [1,2,3,4,5] , aList[1] , aList[1] ]
see aList # print 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
21.15 Passing Lists to Functions
Lists are passed to functions by reference, This means that the called function will work on the same list and can
modify it.
Example:
func main
aList = [1,2,3,4,5] # create list, local in function main
21.13. First-class lists 94
Ring Documentation, Release 1.2
myfunc(aList) # call function, pass list by reference
see aList # print 1 2 3 4 5 6 7 8 9 10
func myfunc list
list + [6,7,8,9,10]
21.16 Access List Items by String Index
Instead of using numbers to determine the item index when we get item value or set item value, We can access items
using string index if the item is a list contains two items and the first item is a string.
Example:
aList = [ ["one",1] , ["two",2] , ["three",3] ]
see aList["one"] + nl +
aList["two"] + nl +
aList["three"] # print 1 2 3
This type of lists can be defined in a better syntax using the : and = operators.
Example:
aList = [ :one = 1 , :two = 2 , :three = 3 ]
see aList["one"] + nl +
aList["two"] + nl +
aList["three"] + nl # print 1 2 3
see aList[1] # print one 1
Tip: using : before identifier (one word) means literal
Note: using = inside list definition create a list of two items where the first item is the left side and the second item is
the right side.
We can add new items to the list using the string index
Example:
aList = []
aList["Egypt"] = "Cairo"
aList["KSA"] = "Riyadh"
see aList["Egypt"] + nl + # print Cairo
aList["KSA"] + nl # print Riyadh
21.17 Passing Parameters Using List
This type of lists is very good for passing parameters to functions Where the order of parameters will not be important
(we can change the order).
Also some parameters maybe optional.
Example:
21.16. Access List Items by String Index 95
Ring Documentation, Release 1.2
myconnect ( [ :server = "myserver.com" , :port = 80 ,
:username = "mahmoud" , :password = "password" ] )
func myconnect mypara
# print connection details
see "User Name : " + mypara[:username] + nl +
"Password : " + mypara[:password] + nl +
"Server : " + mypara[:server] + nl +
"Port : " + mypara[:port]
21.17. Passing Parameters Using List 96
CHAPTER
TWENTYTWO
STRINGS
In this chapter we are going to learn about strings creation and manipulation.
22.1 String Literals
Syntax:
cStr = "This is a string"
cStr2 = 'Another string'
cStr3 = :JustAnotherString
cStr4 = `Yet "another" 'string' ! `
22.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
22.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)
97
Ring Documentation, Release 1.2
22.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
22.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
22.6 Right() Function
We can get a specified number of characters from a string using the Right() function.
22.4. Access String Letters 98
Ring Documentation, Release 1.2
The starting position is the last character on the right.
Syntax:
Right(string,count)
Example:
see Right("Hello World!",6) # print World!
22.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
22.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***
22.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
22.7. Trim() Function 99

More Related Content

What's hot (20)

PDF
The Ring programming language version 1.3 book - Part 11 of 88
Mahmoud Samir Fayed
 
PPTX
Dictionary
Pooja B S
 
PDF
The Ring programming language version 1.7 book - Part 22 of 196
Mahmoud Samir Fayed
 
PPTX
String Manipulation in Python
Pooja B S
 
PPTX
Iteration
Pooja B S
 
PDF
The Ring programming language version 1.10 book - Part 31 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.4 book - Part 19 of 185
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 28 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.1 book - Part 17 of 180
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.8 book - Part 24 of 202
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.2 book - Part 31 of 181
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.4 book - Part 5 of 30
Mahmoud Samir Fayed
 
PDF
Swift the implicit parts
Maxim Zaks
 
PDF
The Ring programming language version 1.2 book - Part 21 of 84
Mahmoud Samir Fayed
 
PPTX
Functions & Recursion
Nishant Munjal
 
PDF
The Ring programming language version 1.4.1 book - Part 5 of 31
Mahmoud Samir Fayed
 
PDF
iRODS Rule Language Cheat Sheet
Samuel Lampa
 
PDF
C++ ARRAY WITH EXAMPLES
Farhan Ab Rahman
 
PDF
The Ring programming language version 1.9 book - Part 25 of 210
Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 11 of 88
Mahmoud Samir Fayed
 
Dictionary
Pooja B S
 
The Ring programming language version 1.7 book - Part 22 of 196
Mahmoud Samir Fayed
 
String Manipulation in Python
Pooja B S
 
Iteration
Pooja B S
 
The Ring programming language version 1.10 book - Part 31 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 19 of 185
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 28 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 17 of 180
Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 24 of 202
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 31 of 181
Mahmoud Samir Fayed
 
The Ring programming language version 1.4 book - Part 5 of 30
Mahmoud Samir Fayed
 
Swift the implicit parts
Maxim Zaks
 
The Ring programming language version 1.2 book - Part 21 of 84
Mahmoud Samir Fayed
 
Functions & Recursion
Nishant Munjal
 
The Ring programming language version 1.4.1 book - Part 5 of 31
Mahmoud Samir Fayed
 
iRODS Rule Language Cheat Sheet
Samuel Lampa
 
C++ ARRAY WITH EXAMPLES
Farhan Ab Rahman
 
The Ring programming language version 1.9 book - Part 25 of 210
Mahmoud Samir Fayed
 

Similar to The Ring programming language version 1.2 book - Part 12 of 84 (20)

PDF
The Ring programming language version 1.8 book - Part 27 of 202
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.3 book - Part 22 of 184
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.6 book - Part 24 of 189
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.7 book - Part 26 of 196
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.1 book - Part 21 of 180
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.9 book - Part 29 of 210
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.3 book - Part 14 of 88
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.2 book - Part 22 of 181
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 30 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.4 book - Part 22 of 185
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.4 book - Part 23 of 185
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.7 book - Part 25 of 196
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.2 book - Part 21 of 181
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.6 book - Part 25 of 189
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 45 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.9 book - Part 30 of 210
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.3 book - Part 23 of 184
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.8 book - Part 28 of 202
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.4.1 book - Part 6 of 31
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.9 book - Part 42 of 210
Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 27 of 202
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 22 of 184
Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 24 of 189
Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 26 of 196
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 21 of 180
Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 29 of 210
Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 14 of 88
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 22 of 181
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 30 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 22 of 185
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 23 of 185
Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 25 of 196
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 21 of 181
Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 25 of 189
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 45 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 30 of 210
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 23 of 184
Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 28 of 202
Mahmoud Samir Fayed
 
The Ring programming language version 1.4.1 book - Part 6 of 31
Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 42 of 210
Mahmoud Samir Fayed
 
Ad

More from Mahmoud Samir Fayed (20)

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

Recently uploaded (20)

PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 

The Ring programming language version 1.2 book - Part 12 of 84

  • 1. Ring Documentation, Release 1.2 Example: aList = ["one","two"] add(aList,"three") see aList Also we can do that using the + operator. Syntax: List + item Example: aList = 1:10 # create list contains numbers from 1 to 10 aList + 11 # add number 11 to the list see aList # print the list 21.3 Get List Size We can get the list size using the len() function Syntax: Len(List) Example: aList = 1:20 see len(aList) # print 20 21.4 Delete Item From List To delete an item from the list, we can use the del() function Syntax: del(list,index) Example: aList = ["one","two","other","three"] Del(aList,3) # delete item number three see aList # print one two three 21.5 Get List Item To get an item from the list, we uses the next syntax List[Index] Example: aList = ["Cairo","Riyadh"] see "Egypt : " + aList[1] + nl + "KSA : " + aList[2] + nl 21.3. Get List Size 90
  • 2. Ring Documentation, Release 1.2 21.6 Set List Item To set the value of an item inside the list, we can use the next syntax List[Index] = Expression Example: aList = list(3) # create list contains three items aList[1] = "one" aList[2] = "two" aList[3] = "three" see aList 21.7 Search To find an item inside the list we can use the find() function Syntax: Find(List,ItemValue) ---> Item Index Find(List,ItemValue,nColumn) ---> Search in nColumn, returns the Item Index Find(List,ItemValue,nColumn,cAttribute) ---> Item Index Example: aList = ["one","two","three","four","five"] see find(aList,"three") # print 3 Example: mylist = [["one",1], ["two",2], ["three",3]] see find(mylist,"two",1) + nl # print 2 see find(mylist,2,2) + nl # print 2 Also we can use the binarysearch() function to search in sorted list. Syntax: BinarySearch(List,ItemValue) ---> Item Index BinarySearch(List,ItemValue,nColumn) ---> Search in nColumn, returns the Item Index Example: aList = ["one","two","three","four","five"] aList = sort(aList) see binarysearch(aList,"three") Output: five four one three two 4 21.6. Set List Item 91
  • 3. Ring Documentation, Release 1.2 21.8 Sort We can sort the list using the sort() function. Syntax: Sort(List) ---> Sorted List Sort(List,nColumn) ---> Sorted List based on nColumn Sort(List,nColumn,cAttribute) ---> Sorted List based on Object Attribute Example: aList = [10,12,3,5,31,15] aList = sort(aList) see aList # print 3 5 10 12 15 31 We can sort list of strings Example: mylist = ["mahmoud","samir","ahmed","ibrahim","mohammed"] see mylist # print list before sorting mylist = sort(mylist) # sort list see "list after sort"+nl see mylist # print ahmed ibrahim mahmoud mohammed samir We can sort a list based on a specific column. Example: aList = [ ["mahmoud",15000] , ["ahmed", 14000 ] , ["samir", 16000 ] , ["mohammed", 12000 ] , ["ibrahim",11000 ] ] aList2 = sort(aList,1) see aList2 Output: ahmed 14000 ibrahim 11000 mahmoud 15000 mohammed 12000 samir 16000 21.9 Reverse We can reverse a list using the reverse() function. Syntax: 21.8. Sort 92
  • 4. Ring Documentation, Release 1.2 Reverse(List) ---> Reversed List Example: aList = [10,20,30,40,50] aList = reverse(aList) see aList # print 50 40 30 20 10 21.10 Insert Items To insert an item in the list we can use the insert() function. Syntax: Insert(List,Index,Item) The inserted item will be AFTER the Index Example: aList = ["A","B","D","E"] insert(aList,2,"C") # Inserts AFTER Index 2, "C" into Position 3 see aList # print A B C D E 21.11 Nested Lists The list may contain other lists Example: aList = [ 1 , [10,20,30] , 5 , [100,1000,5000] ] aList2 = [ "one","two", [3,4], [20,30], ["three", "four", "five",[100,200,300] ] ] see aList[2] # print 10 20 30 see aList[4][3] + nl # print 5000 see aList2[5][2] + nl # print four see aList2[5][4][3] # print 300 21.12 Copy Lists We can copy lists (including nested lists) using the Assignment operator. Example: 21.10. Insert Items 93
  • 5. Ring Documentation, Release 1.2 aList = [ "one","two", [3,4], [20,30], ["three", "four", "five",[100,200,300] ] ] aList2 = aList # Copy aList to aList2 aList2[5] = "other" # modify item number five see aList2[5] + nl # print other see aList[5] # print three four five 100 200 300 21.13 First-class lists Lists are first-class citizens where we can store lists in variables, pass lists to functions, and return lists from functions. Example: aList = duplicate( [1,2,3,4,5] ) see aList[10] + nl # print 5 see mylist() # print 10 20 30 40 50 func duplicate list nMax = len(list) for x = 1 to nMax list + list[x] next return list func mylist return [10,20,30,40,50] 21.14 Using Lists during definition We can use the list items while we are defining the list for the first time. Example: aList = [ [1,2,3,4,5] , aList[1] , aList[1] ] see aList # print 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 21.15 Passing Lists to Functions Lists are passed to functions by reference, This means that the called function will work on the same list and can modify it. Example: func main aList = [1,2,3,4,5] # create list, local in function main 21.13. First-class lists 94
  • 6. Ring Documentation, Release 1.2 myfunc(aList) # call function, pass list by reference see aList # print 1 2 3 4 5 6 7 8 9 10 func myfunc list list + [6,7,8,9,10] 21.16 Access List Items by String Index Instead of using numbers to determine the item index when we get item value or set item value, We can access items using string index if the item is a list contains two items and the first item is a string. Example: aList = [ ["one",1] , ["two",2] , ["three",3] ] see aList["one"] + nl + aList["two"] + nl + aList["three"] # print 1 2 3 This type of lists can be defined in a better syntax using the : and = operators. Example: aList = [ :one = 1 , :two = 2 , :three = 3 ] see aList["one"] + nl + aList["two"] + nl + aList["three"] + nl # print 1 2 3 see aList[1] # print one 1 Tip: using : before identifier (one word) means literal Note: using = inside list definition create a list of two items where the first item is the left side and the second item is the right side. We can add new items to the list using the string index Example: aList = [] aList["Egypt"] = "Cairo" aList["KSA"] = "Riyadh" see aList["Egypt"] + nl + # print Cairo aList["KSA"] + nl # print Riyadh 21.17 Passing Parameters Using List This type of lists is very good for passing parameters to functions Where the order of parameters will not be important (we can change the order). Also some parameters maybe optional. Example: 21.16. Access List Items by String Index 95
  • 7. Ring Documentation, Release 1.2 myconnect ( [ :server = "myserver.com" , :port = 80 , :username = "mahmoud" , :password = "password" ] ) func myconnect mypara # print connection details see "User Name : " + mypara[:username] + nl + "Password : " + mypara[:password] + nl + "Server : " + mypara[:server] + nl + "Port : " + mypara[:port] 21.17. Passing Parameters Using List 96
  • 8. CHAPTER TWENTYTWO STRINGS In this chapter we are going to learn about strings creation and manipulation. 22.1 String Literals Syntax: cStr = "This is a string" cStr2 = 'Another string' cStr3 = :JustAnotherString cStr4 = `Yet "another" 'string' ! ` 22.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 22.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) 97
  • 9. Ring Documentation, Release 1.2 22.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 22.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 22.6 Right() Function We can get a specified number of characters from a string using the Right() function. 22.4. Access String Letters 98
  • 10. Ring Documentation, Release 1.2 The starting position is the last character on the right. Syntax: Right(string,count) Example: see Right("Hello World!",6) # print World! 22.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 22.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*** 22.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 22.7. Trim() Function 99