Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
The Ring programming language version 1.10 book - Part 45 of 212
1. Ring Documentation, Release 1.10
48.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
48.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
48.52 EpochTime() function
Return the Epoch Time
Syntax:
EpochTime(cDate,cTime) ---> nEpochTime
Example:
see EpochTime( Date(), Time() )
48.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
48.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:
48.50. TrimLeft() function 408
2. Ring Documentation, Release 1.10
aList = ListAllFiles("c:/ring/ringlibs","ring") # *.ring only
aList = sort(aList)
see aList
Example:
see listallfiles("b:/ring/ringlibs/weblib","") # All Files
48.55 SystemSilent() Function
We can execute system commands using the SystemSilent() function to avoid displaying the output!
Syntax:
SystemSilent(cCommand)
48.56 OSCreateOpenFolder() Function
Create folder then change the current folder to this new folder
Syntax:
OSCreateOpenFolder(cCommand)
48.57 OSCopyFolder() Function
Copy folder to the current folder
Parameters : The path to the parent folder and the folder name to copy
Syntax:
OSCopyFolder(cParentFolder,cFolderName)
Example
To copy the folder b:ringringlibsstdlib to the current folder
OSCopyFolder("b:ringringlibs","stdlib")
48.58 OSDeleteFolder() Function
Delete Folder in the current Directory
Syntax:
OSDeleteFolder(cFolderName)
48.55. SystemSilent() Function 409
3. Ring Documentation, Release 1.10
48.59 OSCopyFile() Function
Copy File to the current directory
Syntax:
OSCopyFile(cFileName)
48.60 OSDeleteFile() Function
Delete File
Syntax:
OSDeleteFile(cFileName)
48.61 OSRenameFile() Function
Rename File
Syntax:
OSRenameFile(cOldFileName,cNewFileName)
48.62 List2Code() Function
This function convert a Ring list during the runtime to Ring source code that we can save to source files.
The list may contains strings, numbers or sub lists.
Example:
load "stdlibcore.ring"
aList = 1:10
? list2Code(aList)
Output:
[
1,2,3,4,5,6,7,8,9,10
]
48.63 Str2ASCIIList()
Convert a string of bytes to a list of numbers where each item represent the ASCII code of one byte in the string.
Syntax:
Str2ASCIIList(String) ---> List of numbers
48.59. OSCopyFile() Function 410
4. Ring Documentation, Release 1.10
48.64 ASCIIList2Str()
Convert a list of numbers where each item represent the ASCII code of one byte to a string of bytes.
Syntax:
ASCIIList2Str(List of numbers) ---> String
Example:
load "stdlibcore.ring"
cStr = "MmMm"
aList = Str2ASCIILIST(cStr)
? aList
cStr2 = ASCIIList2Str(aList)
? cStr2
? len(cStr2)
Output:
77
109
77
109
MmMm
4
48.64. ASCIIList2Str() 411
5. CHAPTER
FORTYNINE
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
• PostgreSQL Class
• Security Class
• Internet Class
49.1 StdBase Class
Attributes:
• vValue : Object Value
412
6. Ring Documentation, Release 1.10
Methods:
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)
49.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
49.2. String Class 413
7. Ring Documentation, Release 1.10
oString = new string(["one","two","three"])
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
49.2. String Class 414
8. Ring Documentation, Release 1.10
Ring programming language
Ring
***Ring*** programming language
******Ring****** programming language
FirstSecond
FirstFirstFirst
FirstFirstFirst
one
two
three
Hello
How are you?
49.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" ] )
49.3. List Class 415
9. Ring Documentation, Release 1.10
for x in oList
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
49.3. List Class 416
10. Ring Documentation, Release 1.10
three
four
49.4 Stack Class
Parent Class : List Class
Methods:
Method Description/Output
Init(String|Number|List)
Push(Value) Push item to the stack
Pop() Pop item from the stack
Print() Print the stack items
example:
Load "stdlib.ring"
oStack = new Stack
oStack.push(1)
oStack.push(2)
oStack.push(3)
see oStack.pop() + nl
see oStack.pop() + nl
see oStack.pop() + nl
oStack.push(4)
see oStack.pop() + nl
oStack { push("one") push("two") push("three") }
oStack.print()
output:
3
2
1
4
three
two
one
49.5 Queue Class
Parent Class : List Class
Methods:
Method Description/Output
Init(String|Number|List)
Remove() Remove item from the Queue.
example:
Load "stdlib.ring"
oQueue = new Queue
49.4. Stack Class 417