PDA

View Full Version : String.lastIndexOf()


kentyler
04-25-2003, 06:21 AM
even odder, lastIndexOf() seems to respect the "start" parameter, but to not work correctly if there is no start parameter

<canvas debug="true">
<script>
<![CDATA[
x = new string("now is the time"); // returns a string object
debug.write( x.lastIndexOf("i") + " is the last postion of 'i' in the string " + x );
// returns 12, should return 2
debug.write( x.lastIndexOf("i", 6) + " is the last postion of 'i' in the string " + x + " if we start looking from the 2nd postion" );
// returns 4
]]>
</script>
</canvas>

antun
04-25-2003, 06:58 AM
lastIndexOf() returns the position of the last occurence of the substring before the start index, so:


debug.write( x.lastIndexOf("i") + " is the last postion of 'i' in the string " + x );
// returns 12, should return 2


... is correct (there is an i in time). If not specified, the start index defaults to the length of the string-1.

-Antun