With
this information, you can search for the locations of each ampersand and assignment operator and
extract the information between them for use in your Hash object.
Chapter 3: Learning the Basics
69
The StringTools Class
The StringTools class provides a number of simple methods used for tidying your strings or
converting them into a safe format. It may be that you need to remove erroneous spaces from the
beginning or end of a string submitted by the user of your application. Maybe you are transferring them
across the Internet and wish to prepare the string so it is not mangled in the delivery process or you are
simply storing the string in a file or database and want to prepare first. Whatever it is, StringTools
can help.
Table 3 - 11 details the methods of the StringTools class.
Table 3-11
StringTools Method Description
baseDecode(s : String, base :
String) : String
Returns a decoded version of an encoded string
from a given base (must be power of 2)
baseEncode(s : String, base :
String) : String
Returns an encoded version of a string from a given
base (must be power of 2)
endsWith(s : String, end : String) :
Bool
Returns true if a string ends with the given
character or string
hex(n : Int, ?digits : Int) : String Encodes a number into a hexadecimal representation,
with an optional number of zeros for left padding
htmlEscape(s : String) : String Returns a copy of the string with all necessary
symbols escaped for display in an HTML browser
htmlUnescape(s : String) : String Returns an unescaped copy of an htmlEscaped string
isSpace(s : String, pos : Int) :
Bool
Returns true if a given location in a string is a space
character
lpad(s : String, c : String,
l : Int) : String
Returns a copy of a string with the left-hand side
padded with a given character or string a given
number of times
ltrim(s : String) : String Returns a copy of a string with all spaces on the left
of the string removed
replace(s : String, sub : String,
by : String) : String
Returns a copy of a string with all occurrences of a
given character or string replaced for another given
character or string
rpad(s : String, c : String,
l : Int) : String
Returns a copy of a string with the right-hand side
padded with a given character or string a given
number of times
rtrim(s : String) : String Returns a copy of a string with all spaces on the
right of the string removed
Table continued on following page
Part I: The Core Language
70
StringTools Method Description
startsWith(s : String, start :
String) : Bool
Returns true if a string starts with the given
character or string
trim(s : String) : String Returns a copy of a string with all spaces on both
ends of the string removed
urlDecode(s : String) : String Returns a decoded copy of a URL-encoded string
urlEncode(s : String) : String Returns a copy of a string encoded for transport
within a URL
Dealing with Unwanted Spaces
It is common for strings retrieved from the user to contain unwanted spaces.
Pages:
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171