Вы находитесь на странице: 1из 10

Ring Documentation, Release 1.

43.37 matrixmulti() function

Multiply two matrices together.


Syntax:
Matrixmulti(List,List) ---> List

Example:
Load "stdlib.ring"

# Multiply two matrices together.


Puts("Test Matrixmulti()")
A = [[1,2,3], [4,5,6], [7,8,9]]
B = [[1,0,0], [0,1,0], [0,0,1]]
see Matrixmulti(A, B)

43.38 matrixtrans() function

Transpose an arbitrarily sized rectangular Matrix.


Syntax:
Matrixtrans(List) ---> List

Example:
Load "stdlib.ring"

# Transpose an arbitrarily sized rectangular Matrix.


Puts("Test Matrixtrans()")
matrix = [[78,19,30,12,36], [49,10,65,42,50], [30,93,24,78,10], [39,68,27,64,29]]
see Matrixtrans(matrix)

43.39 dayofweek() function

Return the day of the week of given date. (yyyy-mm-dd)


Syntax:
dayofweek(string) ---> string

Example:
Load "stdlib.ring"

# Return the day of the week of given date.


Puts("Test Dayofweek()")
date = "2016-04-24"
see "Data : " + date + " - Day : " + Dayofweek(date) + nl

43.37. matrixmulti() function 295


Ring Documentation, Release 1.5

43.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

43.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)

43.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.

43.40. permutation() function 296


Ring Documentation, Release 1.5

Puts("Test Substring()")
a = "abcxyzqweabc"
b = "abc"
i = 4
see substring(a,b,i)

43.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

43.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

43.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

43.43. changestring() function 297


Ring Documentation, Release 1.5

43.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") )

43.47 makedir() function

Make Directory
Syntax:
MakeDir(String)

Example:
Load "stdlib.ring"

# Create Directory
puts("create Directory : myfolder")
makedir("myfolder")

43.48 fsize() function

The function return the file size in bytes.


Syntax:
FSize(File Handle) ---> Number (File Size in Bytes)

43.49 trimall() function

Remove all spaces and tabs characters from a string


Syntax:
TrimAll(cString) ---> cString # Without Spaces and Tabs

43.46. direxists() function 298


Ring Documentation, Release 1.5

43.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

43.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

43.52 epochtime() function

Return the Epoch Time


Syntax:
EpochTime(cDate,cTime) ---> nEpochTime

Example:
see EpochTime( Date(), Time() )

43.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

43.54 ListAllFiles() Function

Using this function we can quickly do a process on a group of files in a folder and its sub folders.
Syntax:
ListAllFiles(cFolder,cExtension) ---> List of Files

Example:

43.50. trimleft() function 299


Ring Documentation, Release 1.5

aList = ListAllFiles("c:/ring/ringlibs","ring") # *.ring only


aList = sort(aList)
see aList

Example:
see listallfiles("b:/ring/ringlibs/weblib","") # All Files

43.54. ListAllFiles() Function 300


CHAPTER

FORTYFOUR

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

44.1 StdBase Class

Attributes:
vValue : Object Value
Methods:

301
Ring Documentation, Release 1.5

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)

44.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"])

44.2. String Class 302


Ring Documentation, Release 1.5

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

44.2. String Class 303


Ring Documentation, Release 1.5

Ring
***Ring*** programming language
******Ring****** programming language
FirstSecond
FirstFirstFirst
FirstFirstFirst
one
two
three
Hello
How are you?

44.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

44.3. List Class 304

Вам также может понравиться