OSDN Git Service

【更新内容】
[ring-lang-081/ring.git] / docs / en / source / zerolib.txt
1 .. index:: 
2         Single: Using ZeroLib;  Introduction
3
4 =============
5 Using ZeroLib
6 =============
7
8 In this chapter we will learn how to use the ZeroLib library.
9
10
11 .. index:: 
12         pair: Using ZeroLib; Introduction
13
14 Introduction
15 ============
16
17 ZeroLib is a simple library written in Ring.
18
19 The library provideds classes for Lists and String where the index starts from 0.
20
21
22 .. index:: 
23         pair: Using ZeroLib; Z() function
24
25 Z() function
26 ============
27
28 Syntax:
29
30 .. code-block:: none
31
32         Z(String|List) ---> New Object (ZeroBasedString|ZeroBasedList)
33
34 .. index:: 
35         pair: Using ZeroLib; ZeroBasedList Class
36
37 ZeroBasedList Class
38 ===================
39
40 Simple class provide a List where the index starts from zero.
41
42 Methods:
43
44 ===========================     ======================================================================
45 Method                                          Description/Output
46 ===========================     ======================================================================
47 Init(List)                      
48 Add(Value)                      Add item to the list
49 Insert(nIndex,Value)            Inset Item after nIndex
50 Find(Value)                     Find item
51 Delete(nIndex)                  Delete item from the list 
52 Item(nIndex)                    Get item from the list
53 First()                         Get the first item in the list
54 Last()                          Get the last item in the list
55 Set(nIndex,Value)               Set item value
56 FindInColumn(nCol,Value)        Find item in a column 
57 Sort()                          Sort items - return new list
58 Reverse()                       Reverse items - return new list
59 Swap(nIndex1,nIndex2)           Swap two items
60 ===========================     ======================================================================
61
62
63 Example:
64
65 .. code-block:: ring
66
67         load "zerolib.ring"
68
69         ? "Using List - Index start from 0"
70         List = Z( [1,2,3] )
71         List.Add(4)
72         List.Add(5)
73         ? List[0]
74         ? List[1]
75         ? List[2]
76         ? List[3]
77         ? List[4]
78         nIndex = List.find(2)
79         ? "Find(2) = " + nIndex
80         List.delete(0)
81         ? "After deleting the first item : List[0]" 
82         ? "Now List[0] = " + List[0] 
83
84 Output:
85
86 .. code-block:: ring 
87
88         Using List - Index start from 0
89         1
90         2
91         3
92         4
93         5
94         Find(2) = 1
95         After deleting the first item : List[0]
96         Now List[0] = 2
97
98 .. index:: 
99         pair: Using ZeroLib; ZeroBasedString Class
100
101 ZeroBasedString Class
102 =====================
103
104 Simple class provide a String where the index starts from zero.
105
106 ===========================     ======================================================================
107 Method                          Description/Output
108 ===========================     ======================================================================
109 Init(String|Number) 
110 Lower()                         New String - Lower case characters
111 Upper()                         New String - Upper case characters
112 Left(x)                         New String - contains x characters from the left
113 Right(x)                        New String - contains x characters from the right
114 Lines()                         Number - Lines count
115 Trim()                          New String - Remove Spaces
116 Copy(x)                         New String - repeat string x times
117 strcmp(cString)                 Compare string with cString  
118 tolist()                        List (String Lines to String Items)
119 tofile(cFileName)               Write string to file
120 mid(nPos1,nPos2)                New String - from nPos1 to nPos2
121 getfrom(nPos1)                  New String - from nPos1 to the end of the string
122 replace(cStr1,cStr2,lCase)      New String - Replace cStr1 with cStr2 , lCase (True=Match Case)
123 split()                         List - Each Word as list item
124 startswith(substring)           Return true if the start starts with a substring 
125 endswith(substring)             Return true if the start ends with a substring
126 ===========================     ======================================================================
127
128 Example:
129
130 .. code-block:: ring
131
132         load "zerolib.ring"
133
134         ? "Using String - Index start from 0"
135         String = Z( "Welcome" )
136         ? String[0]
137         ? String[1]
138         ? String[2]
139         ? String[3]
140         ? String[4]
141         ? String[5]
142         ? String[6]
143
144 Output:
145
146 .. code-block:: ring 
147
148         Using String - Index start from 0
149         W
150         e
151         l
152         c
153         o
154         m
155         e
156
157 .. index:: 
158         pair: Using ZeroLib; Source Code
159
160 Source Code
161 ===========
162
163 We can find the library source code in this folder 
164
165 URL : https://github.com/ring-lang/ring/tree/master/ringlibs/zerolib
166
167
168