Sie sind auf Seite 1von 10

Ring Documentation, Release 1.5.

see "" + aList[i] + " "


next

42.34 palindrome() function

Check if a sequence of characters is a palindrome or not.


Syntax:
Palindrome(String) ---> True/False

Example:
Load "stdlib.ring"

Puts("Test Palindrome()")
cString = "radar"
see Palindrome(cString)

42.35 isleapyear() function

Check whether a given year is a leap year in the Gregorian calendar.


Syntax:
Isleapyear(number) ---> True/False

Example:
Load "stdlib.ring"

Puts("Test Isleapyear()")
year = 2016
if Isleapyear(year) see "" + year + " is a leap year."
else see "" + year + " is not a leap year." ok

42.36 binarydigits() function

Compute the sequence of binary digits for a given non-negative integer.


Syntax:
binarydigits(number) ---> string

Example:
Load "stdlib.ring"

Puts("Test Binarydigits()")
b = 35
see "Binary digits of " + b + " = " + Binarydigits(b)

42.34. palindrome() function 315


Ring Documentation, Release 1.5.4

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

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

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

42.37. matrixmulti() function 316


Ring Documentation, Release 1.5.4

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 317


Ring Documentation, Release 1.5.4

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 318


Ring Documentation, Release 1.5.4

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 319


Ring Documentation, Release 1.5.4

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 320


Ring Documentation, Release 1.5.4

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 321


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:

322
Ring Documentation, Release 1.5.4

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 323


Ring Documentation, Release 1.5.4

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 324

Das könnte Ihnen auch gefallen