Prev | Current Page 156 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

indexOf(???e???, 4); // will return 10
var location : Int = str.indexOf(???e???, 11); // will return -1
As well as searching through a string with indexOf , you can also perform the same feat in reverse,
starting at the end of the string, with the lastIndexOf method:
var location : Int = str.lastIndexOf(???e???); // will return 10 from ???haXe and Neko???
When searching a string, it often helps to know how long the string is. You can do this by querying the
string ??™ s length property:
var lengthOfString : Int = str.length; // will return 13 from ???haXe and Neko???
Converting a String to an Array
Finally, if performing functions against a string as though it were an Array isn ??™ t quite enough, you can
convert a string to an actual Array of strings or characters ( Array < String > ) using the split method.
The split method takes only one parameter: a delimiter. A delimiter is a character or string that
represents the middle of the Array items in your string. Therefore, in a string where a comma separates
the items, using the comma as the delimiter will extract the items themselves and store them in the
Array:
var items : String = ???item1,item2,item3???;
var itemArray : Array < String > = items.


Pages:
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168