SlideShare a Scribd company logo
Ring Documentation, Release 1.5.3
42.40 permutation() function
Generates all permutations of n different numerals.
Syntax:
permutation(list)
Example:
Load "stdlib.ring"
# Generates all permutations of n different numerals
Puts("Test Permutation()")
list = [1, 2, 3, 4]
for perm = 1 to 24
for i = 1 to len(list)
see list[i] + " "
next
see nl
Permutation(list)
next
42.41 readline() function
Read line from file
Syntax:
readline(fp) ---> string
Example:
Load "stdlib.ring"
# Read a file line by line.
Puts("Test Readline()")
fp = fopen("test.ring","r")
while not feof(fp)
See Readline(fp) end
fclose(fp)
42.42 substring() function
Return a position of a substring starting from a given position in a string.
Syntax:
Substring(str,substr,npos) ---> string
Example:
Load "stdlib.ring"
# Return a position of a substring starting from a given position in a string.
42.40. permutation() function 315
Ring Documentation, Release 1.5.3
Puts("Test Substring()")
a = "abcxyzqweabc"
b = "abc"
i = 4
see substring(a,b,i)
42.43 changestring() function
Change substring from given position to a given position with another substring.
Syntax:
Changestring(cString, nPos1, nPos2, cSubstr) ---> cString
Example:
Load "stdlib.ring"
# Change substring from given position for given position with a substring.
Puts("Test Changestring()")
see Changestring("Rmasdg",2,5,"in") # Ring
42.44 sleep() function
Sleep for the given amount of time.
Syntax:
sleep(nSeconds)
Example:
Load "stdlib.ring"
Puts("Test Sleep()")
see "Wait 3 Seconds!"
Sleep(3)
see nl
42.45 ismainsourcefile() function
Check if the current file is the main source file
Syntax:
IsMainSourceFile() ---> True/False
Example:
Load "stdlib.ring"
if ismainsourcefile()
# code
ok
42.43. changestring() function 316
Ring Documentation, Release 1.5.3
42.46 direxists() function
Check if directory exists
Syntax:
DirExists(String) ---> True/False
Example:
Load "stdlib.ring"
see "Check dir : b:ring "
puts( DirExists("b:ring") )
see "Check dir : C:ring "
Puts( DirExists("C:ring") )
42.47 makedir() function
Make Directory
Syntax:
MakeDir(String)
Example:
Load "stdlib.ring"
# Create Directory
puts("create Directory : myfolder")
makedir("myfolder")
42.48 fsize() function
The function return the file size in bytes.
Syntax:
FSize(File Handle) ---> Number (File Size in Bytes)
42.49 trimall() function
Remove all spaces and tabs characters from a string
Syntax:
TrimAll(cString) ---> cString # Without Spaces and Tabs
42.46. direxists() function 317
Ring Documentation, Release 1.5.3
42.50 trimleft() function
Remove all spaces and tabs characters from the left side of a string
Syntax:
TrimLeft(cString) ---> cString # Without Spaces and Tabs from the left side
42.51 trimright() function
Remove all spaces and tabs characters from the right side of a string
Syntax:
TrimRight(cString) ---> cString # Without Spaces and Tabs from the right side
42.52 epochtime() function
Return the Epoch Time
Syntax:
EpochTime(cDate,cTime) ---> nEpochTime
Example:
see EpochTime( Date(), Time() )
42.53 SystemCmd() Function
We can execute system commands using the SystemCmd() function that outputs to a variable
Syntax:
SystemCmd(cCommand)
Example:
cYou = SystemCmd("whoami") # User Name logged in is output a variable
cThem = SystemCmd("dir c:Users") # Directory List is output to a variable
42.54 ListAllFiles() Function
Using this function we can quickly do a process on a group of files in a folder and it’s sub folders.
Syntax:
ListAllFiles(cFolder,cExtension) ---> List of Files
Example:
42.50. trimleft() function 318
Ring Documentation, Release 1.5.3
aList = ListAllFiles("c:/ring/ringlibs","ring") # *.ring only
aList = sort(aList)
see aList
Example:
see listallfiles("b:/ring/ringlibs/weblib","") # All Files
42.54. ListAllFiles() Function 319
CHAPTER
FORTYTHREE
STDLIB CLASSES
In this chapter we are going to learn about the classes in the stdlib.ring
• StdBase Class
• String Class
• List Class
• Stack Class
• Queue Class
• HashTable Class
• Tree Class
• Math Class
• DateTime Class
• File Class
• System Class
• Debug Class
• DataType Class
• Conversion Class
• ODBC CLass
• MySQL Class
• SQLite Class
• Security Class
• Internet Class
43.1 StdBase Class
Attributes:
• vValue : Object Value
Methods:
320
Ring Documentation, Release 1.5.3
Method Description/Output
Init(x) Set vValue Attribute to x value
Print() Print vValue
PrintLn() Print vValue then New Line
Size() return number represent the size of vValue
Value() return vValue
Set(x) Call Init(x)
43.2 String Class
Parent Class : StdBase Class
Methods:
Method Description/Output
Init(String|Number|List)
Lower() New String - Lower case characters
Upper() New String - Upper case characters
Left(x) New String - contains x characters from the left
Right(x) New String - contains x characters from the right
Lines() Number - Lines count
Trim() New String - Remove Spaces
Copy(x) New String - repeat string x times
strcmp(cString) Compare string with cString
tolist() List (String Lines to String Items)
tofile(cFileName) Write string to file
mid(nPos1,nPos2) New String - from nPos1 to nPos2
getfrom(nPos1) New String - from nPos1 to the end of the string
replace(cStr1,cStr2,lCase) New String - Replace cStr1 with cStr2 , lCase (True=Match Case)
split() List - Each Word as list item
startswith(substring) Return true if the start starts with a substring
endswith(substring) Return true if the start ends with a substring
Example:
Load "stdlib.ring"
See "Testing the String Class" + nl
oString = new string("Hello, World!")
oString.println()
oString.upper().println()
oString.lower().println()
oString.left(5).println()
oString.right(6).println()
oString = new string("Hi" + nl + "Hello" )
See oString.lines() + nl
oString = new string(" Welcome ")
oString.println()
oString.trim().println()
oString = new string("Hello! ")
oString.copy(3).println()
see oString.strcmp("Hello! ") + nl
see oString.strcmp("Hello ") + nl
see oString.strcmp("Hello!! ") + nl
oString = new string(["one","two","three"])
43.2. String Class 321
Ring Documentation, Release 1.5.3
oString.print()
see oString.lines() + nl
oString = new String(1234)
oString.println()
oString = new String("one"+nl+"two"+nl+"three")
aList = oString.tolist()
see "List Items" + nl See aList
oString = new String( "Welcome to the Ring programming language")
See "the - position : " + oString.pos("the") + nl
oString = oString.getfrom(oString.pos("Ring"))
oString.println()
oString.mid(1,4).println()
oString = oString.replace("Ring","***Ring***",true)
oString.println()
oString = oString.replace("ring","***Ring***",false)
oString.println()
oString1 = new string("First")
oString2 = new string("Second")
oString = oString1 + oString2
oString.println()
oString = oString1 * 3
oString.println()
for t in ostring see t next
oString.tofile("test.txt")
oString = new string("one two three")
see nl
see ostring.split()
oString {
set("Hello") println()
set("How are you?") println()
}
Output:
Testing the String Class
Hello, World!
HELLO, WORLD!
hello, world!
Hello
World!
2
Welcome
Welcome
Hello! Hello! Hello!
0
1
-1
one
two
three
4
1234
List Items
one
two
three
the - position : 12
Ring programming language
43.2. String Class 322
Ring Documentation, Release 1.5.3
Ring
***Ring*** programming language
******Ring****** programming language
FirstSecond
FirstFirstFirst
FirstFirstFirst
one
two
three
Hello
How are you?
43.3 List Class
Parent Class : StdBase Class
Methods:
Method Description/Output
Init(String|List)
Add(Value) Add item to the list
Delete(nIndex) Delete item from the list
Item(nIndex) Get item from the list
First() Get the first item in the list
Last() Get the last item in the list
Set(nIndex,Value) Set item value
FindInColumn(nCol,Value) Find item in a column
Sort() Sort items - return new list
Reverse() Reverse items - return new list
Insert(nIndex,Value) Inset Item after nIndex
example:
Load "stdlib.ring"
oList = new list ( [1,2,3] )
oList.Add(4)
oList.print()
see oList.item(1) + nl
oList.delete(4)
oList.print()
see oList.first() + nl
see oList.last() + nl
oList { set(1,"one") set(2,"two") set(3,"three") print() }
see oList.find("two") + nl
oList.sort().print()
oList.reverse().print()
oList.insert(2,"nice")
oList.print()
oList = new list ( [ [1,"one"],[2,"two"],[3,"three"] ] )
see copy("*",10) + nl
oList.print()
see "Search two : " + oList.findincolumn(2,"two") + nl
see "Search 1 : " + oList.findincolumn(1,1) + nl
oList = new list ( [ "Egypt" , "USA" , "KSA" ] )
for x in oList
43.3. List Class 323
Ring Documentation, Release 1.5.3
see x + nl
next
oList = new list ( [1,2,3,4] )
oList + [5,6,7]
oList.print()
oList = new list ( ["one","two"] )
oList2 = new list ( ["three","four"] )
oList + oList2
oList.print()
output:
1
2
3
4
1
1
2
3
1
3
one
two
three
2
one
three
two
three
two
one
one
two
nice
three
**********
1
one
2
two
3
three
Search two : 2
Search 1 : 1
Egypt
USA
KSA
1
2
3
4
5
6
7
one
two
three
43.3. List Class 324

More Related Content

PDF
The Ring programming language version 1.3 book - Part 26 of 88
PDF
The Ring programming language version 1.5.4 book - Part 35 of 185
PDF
The Ring programming language version 1.6 book - Part 37 of 189
PDF
The Ring programming language version 1.10 book - Part 45 of 212
PDF
The Ring programming language version 1.5.2 book - Part 34 of 181
PDF
The Ring programming language version 1.4.1 book - Part 10 of 31
PDF
The Ring programming language version 1.9 book - Part 124 of 210
PDF
The Ring programming language version 1.8 book - Part 117 of 202
The Ring programming language version 1.3 book - Part 26 of 88
The Ring programming language version 1.5.4 book - Part 35 of 185
The Ring programming language version 1.6 book - Part 37 of 189
The Ring programming language version 1.10 book - Part 45 of 212
The Ring programming language version 1.5.2 book - Part 34 of 181
The Ring programming language version 1.4.1 book - Part 10 of 31
The Ring programming language version 1.9 book - Part 124 of 210
The Ring programming language version 1.8 book - Part 117 of 202

What's hot (20)

PDF
The Ring programming language version 1.5.1 book - Part 33 of 180
PDF
The Ring programming language version 1.8 book - Part 94 of 202
PDF
Strings part2
PPTX
String Handling in c++
PPT
Headerfiles
PDF
Functional programming in C++ LambdaNsk
PDF
The Ring programming language version 1.10 book - Part 31 of 212
PDF
The Ring programming language version 1.9 book - Part 123 of 210
PDF
C++ extension methods
PDF
Strinng Classes in c++
PDF
C++ ARRAY WITH EXAMPLES
PDF
The Ring programming language version 1.3 book - Part 25 of 88
PDF
Programming in lua STRING AND ARRAY
PPTX
String in python use of split method
PDF
The Ring programming language version 1.2 book - Part 24 of 84
PDF
The Ring programming language version 1.10 book - Part 35 of 212
PDF
Python Cheat Sheet
PDF
Postgresql 9.3 overview
PDF
05 c++-strings
PPTX
The string class
The Ring programming language version 1.5.1 book - Part 33 of 180
The Ring programming language version 1.8 book - Part 94 of 202
Strings part2
String Handling in c++
Headerfiles
Functional programming in C++ LambdaNsk
The Ring programming language version 1.10 book - Part 31 of 212
The Ring programming language version 1.9 book - Part 123 of 210
C++ extension methods
Strinng Classes in c++
C++ ARRAY WITH EXAMPLES
The Ring programming language version 1.3 book - Part 25 of 88
Programming in lua STRING AND ARRAY
String in python use of split method
The Ring programming language version 1.2 book - Part 24 of 84
The Ring programming language version 1.10 book - Part 35 of 212
Python Cheat Sheet
Postgresql 9.3 overview
05 c++-strings
The string class
Ad

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

PDF
The Ring programming language version 1.7 book - Part 39 of 196
PDF
The Ring programming language version 1.8 book - Part 40 of 202
PDF
The Ring programming language version 1.5.2 book - Part 35 of 181
PDF
The Ring programming language version 1.9 book - Part 44 of 210
PDF
The Ring programming language version 1.9 book - Part 30 of 210
PDF
The Ring programming language version 1.8 book - Part 28 of 202
PDF
The Ring programming language version 1.8 book - Part 41 of 202
PDF
The Ring programming language version 1.5.3 book - Part 23 of 184
PDF
The Ring programming language version 1.6 book - Part 36 of 189
PDF
The Ring programming language version 1.2 book - Part 23 of 84
PDF
The Ring programming language version 1.6 book - Part 25 of 189
PDF
The Ring programming language version 1.3 book - Part 14 of 88
PDF
The Ring programming language version 1.5.4 book - Part 34 of 185
PDF
The Ring programming language version 1.9 book - Part 42 of 210
PDF
The Ring programming language version 1.8 book - Part 39 of 202
PDF
The Ring programming language version 1.5.1 book - Part 34 of 180
PDF
The Ring programming language version 1.5.4 book - Part 23 of 185
PDF
The Ring programming language version 1.4.1 book - Part 6 of 31
PDF
The Ring programming language version 1.5.2 book - Part 33 of 181
PDF
The Ring programming language version 1.5.1 book - Part 35 of 180
The Ring programming language version 1.7 book - Part 39 of 196
The Ring programming language version 1.8 book - Part 40 of 202
The Ring programming language version 1.5.2 book - Part 35 of 181
The Ring programming language version 1.9 book - Part 44 of 210
The Ring programming language version 1.9 book - Part 30 of 210
The Ring programming language version 1.8 book - Part 28 of 202
The Ring programming language version 1.8 book - Part 41 of 202
The Ring programming language version 1.5.3 book - Part 23 of 184
The Ring programming language version 1.6 book - Part 36 of 189
The Ring programming language version 1.2 book - Part 23 of 84
The Ring programming language version 1.6 book - Part 25 of 189
The Ring programming language version 1.3 book - Part 14 of 88
The Ring programming language version 1.5.4 book - Part 34 of 185
The Ring programming language version 1.9 book - Part 42 of 210
The Ring programming language version 1.8 book - Part 39 of 202
The Ring programming language version 1.5.1 book - Part 34 of 180
The Ring programming language version 1.5.4 book - Part 23 of 185
The Ring programming language version 1.4.1 book - Part 6 of 31
The Ring programming language version 1.5.2 book - Part 33 of 181
The Ring programming language version 1.5.1 book - Part 35 of 180
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)

PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
cuic standard and advanced reporting.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Electronic commerce courselecture one. Pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Cloud computing and distributed systems.
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
cuic standard and advanced reporting.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Electronic commerce courselecture one. Pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
MYSQL Presentation for SQL database connectivity
Per capita expenditure prediction using model stacking based on satellite ima...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
20250228 LYD VKU AI Blended-Learning.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Cloud computing and distributed systems.
Programs and apps: productivity, graphics, security and other tools
Understanding_Digital_Forensics_Presentation.pptx
NewMind AI Weekly Chronicles - August'25 Week I

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

  • 1. Ring Documentation, Release 1.5.3 42.40 permutation() function Generates all permutations of n different numerals. Syntax: permutation(list) Example: Load "stdlib.ring" # Generates all permutations of n different numerals Puts("Test Permutation()") list = [1, 2, 3, 4] for perm = 1 to 24 for i = 1 to len(list) see list[i] + " " next see nl Permutation(list) next 42.41 readline() function Read line from file Syntax: readline(fp) ---> string Example: Load "stdlib.ring" # Read a file line by line. Puts("Test Readline()") fp = fopen("test.ring","r") while not feof(fp) See Readline(fp) end fclose(fp) 42.42 substring() function Return a position of a substring starting from a given position in a string. Syntax: Substring(str,substr,npos) ---> string Example: Load "stdlib.ring" # Return a position of a substring starting from a given position in a string. 42.40. permutation() function 315
  • 2. Ring Documentation, Release 1.5.3 Puts("Test Substring()") a = "abcxyzqweabc" b = "abc" i = 4 see substring(a,b,i) 42.43 changestring() function Change substring from given position to a given position with another substring. Syntax: Changestring(cString, nPos1, nPos2, cSubstr) ---> cString Example: Load "stdlib.ring" # Change substring from given position for given position with a substring. Puts("Test Changestring()") see Changestring("Rmasdg",2,5,"in") # Ring 42.44 sleep() function Sleep for the given amount of time. Syntax: sleep(nSeconds) Example: Load "stdlib.ring" Puts("Test Sleep()") see "Wait 3 Seconds!" Sleep(3) see nl 42.45 ismainsourcefile() function Check if the current file is the main source file Syntax: IsMainSourceFile() ---> True/False Example: Load "stdlib.ring" if ismainsourcefile() # code ok 42.43. changestring() function 316
  • 3. Ring Documentation, Release 1.5.3 42.46 direxists() function Check if directory exists Syntax: DirExists(String) ---> True/False Example: Load "stdlib.ring" see "Check dir : b:ring " puts( DirExists("b:ring") ) see "Check dir : C:ring " Puts( DirExists("C:ring") ) 42.47 makedir() function Make Directory Syntax: MakeDir(String) Example: Load "stdlib.ring" # Create Directory puts("create Directory : myfolder") makedir("myfolder") 42.48 fsize() function The function return the file size in bytes. Syntax: FSize(File Handle) ---> Number (File Size in Bytes) 42.49 trimall() function Remove all spaces and tabs characters from a string Syntax: TrimAll(cString) ---> cString # Without Spaces and Tabs 42.46. direxists() function 317
  • 4. Ring Documentation, Release 1.5.3 42.50 trimleft() function Remove all spaces and tabs characters from the left side of a string Syntax: TrimLeft(cString) ---> cString # Without Spaces and Tabs from the left side 42.51 trimright() function Remove all spaces and tabs characters from the right side of a string Syntax: TrimRight(cString) ---> cString # Without Spaces and Tabs from the right side 42.52 epochtime() function Return the Epoch Time Syntax: EpochTime(cDate,cTime) ---> nEpochTime Example: see EpochTime( Date(), Time() ) 42.53 SystemCmd() Function We can execute system commands using the SystemCmd() function that outputs to a variable Syntax: SystemCmd(cCommand) Example: cYou = SystemCmd("whoami") # User Name logged in is output a variable cThem = SystemCmd("dir c:Users") # Directory List is output to a variable 42.54 ListAllFiles() Function Using this function we can quickly do a process on a group of files in a folder and it’s sub folders. Syntax: ListAllFiles(cFolder,cExtension) ---> List of Files Example: 42.50. trimleft() function 318
  • 5. Ring Documentation, Release 1.5.3 aList = ListAllFiles("c:/ring/ringlibs","ring") # *.ring only aList = sort(aList) see aList Example: see listallfiles("b:/ring/ringlibs/weblib","") # All Files 42.54. ListAllFiles() Function 319
  • 6. CHAPTER FORTYTHREE STDLIB CLASSES In this chapter we are going to learn about the classes in the stdlib.ring • StdBase Class • String Class • List Class • Stack Class • Queue Class • HashTable Class • Tree Class • Math Class • DateTime Class • File Class • System Class • Debug Class • DataType Class • Conversion Class • ODBC CLass • MySQL Class • SQLite Class • Security Class • Internet Class 43.1 StdBase Class Attributes: • vValue : Object Value Methods: 320
  • 7. Ring Documentation, Release 1.5.3 Method Description/Output Init(x) Set vValue Attribute to x value Print() Print vValue PrintLn() Print vValue then New Line Size() return number represent the size of vValue Value() return vValue Set(x) Call Init(x) 43.2 String Class Parent Class : StdBase Class Methods: Method Description/Output Init(String|Number|List) Lower() New String - Lower case characters Upper() New String - Upper case characters Left(x) New String - contains x characters from the left Right(x) New String - contains x characters from the right Lines() Number - Lines count Trim() New String - Remove Spaces Copy(x) New String - repeat string x times strcmp(cString) Compare string with cString tolist() List (String Lines to String Items) tofile(cFileName) Write string to file mid(nPos1,nPos2) New String - from nPos1 to nPos2 getfrom(nPos1) New String - from nPos1 to the end of the string replace(cStr1,cStr2,lCase) New String - Replace cStr1 with cStr2 , lCase (True=Match Case) split() List - Each Word as list item startswith(substring) Return true if the start starts with a substring endswith(substring) Return true if the start ends with a substring Example: Load "stdlib.ring" See "Testing the String Class" + nl oString = new string("Hello, World!") oString.println() oString.upper().println() oString.lower().println() oString.left(5).println() oString.right(6).println() oString = new string("Hi" + nl + "Hello" ) See oString.lines() + nl oString = new string(" Welcome ") oString.println() oString.trim().println() oString = new string("Hello! ") oString.copy(3).println() see oString.strcmp("Hello! ") + nl see oString.strcmp("Hello ") + nl see oString.strcmp("Hello!! ") + nl oString = new string(["one","two","three"]) 43.2. String Class 321
  • 8. Ring Documentation, Release 1.5.3 oString.print() see oString.lines() + nl oString = new String(1234) oString.println() oString = new String("one"+nl+"two"+nl+"three") aList = oString.tolist() see "List Items" + nl See aList oString = new String( "Welcome to the Ring programming language") See "the - position : " + oString.pos("the") + nl oString = oString.getfrom(oString.pos("Ring")) oString.println() oString.mid(1,4).println() oString = oString.replace("Ring","***Ring***",true) oString.println() oString = oString.replace("ring","***Ring***",false) oString.println() oString1 = new string("First") oString2 = new string("Second") oString = oString1 + oString2 oString.println() oString = oString1 * 3 oString.println() for t in ostring see t next oString.tofile("test.txt") oString = new string("one two three") see nl see ostring.split() oString { set("Hello") println() set("How are you?") println() } Output: Testing the String Class Hello, World! HELLO, WORLD! hello, world! Hello World! 2 Welcome Welcome Hello! Hello! Hello! 0 1 -1 one two three 4 1234 List Items one two three the - position : 12 Ring programming language 43.2. String Class 322
  • 9. Ring Documentation, Release 1.5.3 Ring ***Ring*** programming language ******Ring****** programming language FirstSecond FirstFirstFirst FirstFirstFirst one two three Hello How are you? 43.3 List Class Parent Class : StdBase Class Methods: Method Description/Output Init(String|List) Add(Value) Add item to the list Delete(nIndex) Delete item from the list Item(nIndex) Get item from the list First() Get the first item in the list Last() Get the last item in the list Set(nIndex,Value) Set item value FindInColumn(nCol,Value) Find item in a column Sort() Sort items - return new list Reverse() Reverse items - return new list Insert(nIndex,Value) Inset Item after nIndex example: Load "stdlib.ring" oList = new list ( [1,2,3] ) oList.Add(4) oList.print() see oList.item(1) + nl oList.delete(4) oList.print() see oList.first() + nl see oList.last() + nl oList { set(1,"one") set(2,"two") set(3,"three") print() } see oList.find("two") + nl oList.sort().print() oList.reverse().print() oList.insert(2,"nice") oList.print() oList = new list ( [ [1,"one"],[2,"two"],[3,"three"] ] ) see copy("*",10) + nl oList.print() see "Search two : " + oList.findincolumn(2,"two") + nl see "Search 1 : " + oList.findincolumn(1,1) + nl oList = new list ( [ "Egypt" , "USA" , "KSA" ] ) for x in oList 43.3. List Class 323
  • 10. Ring Documentation, Release 1.5.3 see x + nl next oList = new list ( [1,2,3,4] ) oList + [5,6,7] oList.print() oList = new list ( ["one","two"] ) oList2 = new list ( ["three","four"] ) oList + oList2 oList.print() output: 1 2 3 4 1 1 2 3 1 3 one two three 2 one three two three two one one two nice three ********** 1 one 2 two 3 three Search two : 2 Search 1 : 1 Egypt USA KSA 1 2 3 4 5 6 7 one two three 43.3. List Class 324