You use one of the methods substring, substr or slice of the String type.
- slice takes two arguments, the starting position and the ending position.
- substr takes two arguments, the starting position and the length of the substring.
If you use a negative position, it will count from the end of the string
- substring behaves the same as slice, except that it doesn't allow its arguments to be negative and thus point from the end of the string.
All of these will terminate at the end of the string if the second argument is left out.
"string".slice(2,4) => "ri"
"string".substr(1,3) => "tri"
"string".substr(-1) => "g"
"string".slice(-5, -2) => "tri"
Last edited by liorean; 05-24-2003 at 02:08 PM..