Prev | Current Page 161 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


StringTools.trim(myStr);
More String Manipulation
You can verify the starting and ending characters of a string using the startsWith and endsWith
methods. Both take the string to examine as the first parameter and a string of one or more characters
you wish to compare as the second parameter:
var isValid : Bool = StringTools.startsWith(myStr, ???haXe???);
// returns true for ???haXe and Neko???
isValid = StringTools.endsWith(myStr, ???rocks???);
// returns false
Sometimes, you might find it necessary to add characters to the ends of your string, so that they might fit
into a field in a database for example. You can do this using the lpad and rpad methods. Both methods
require the string to pad, the string you want to append as padding, and the number of characters the
overall string should be:
var paddedString : String = StringTools.lpad(myStr, ??? ???, 20);
Chapter 3: Learning the Basics
71
Finally, you can replace all occurrences of a particular character or string of characters using the replace
method.


Pages:
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173