Slice (String.slice Method) - MACROMEDIA FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE Reference

Flash lite 2.x actionscript language reference
Hide thumbs Also See for FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE:
Table of Contents

Advertisement

slice (String.slice method)

public slice(start:Number, end:Number) : String
Returns a string that includes the
character and all characters up to, but not including,
start
the
character. The original String object is not modified. If the
parameter is not
end
end
specified, the end of the substring is the end of the string. If the character indexed by
is
start
the same as or to the right of the character indexed by
, the method returns an empty
end
string.
Availability: ActionScript 1.0; Flash Lite 2.0
Parameters
- The zero-based index of the starting point for the slice. If
is a negative
start:Number
start
number, the starting point is determined from the end of the string, where -1 is the last
character.
- An integer that is one greater than the index of the ending point for the slice.
end:Number
The character indexed by the
parameter is not included in the extracted string. If this
end
parameter is omitted,
is used. If
is a negative number, the ending point is
String.length
end
determined by counting back from the end of the string, where -1 is the last character.
Returns
- A substring of the specified string.
String
Example
The following example creates a variable,
assigns it a String value, and then calls the
my_str,
method using a variety of values for both the
and
parameters. Each call to
slice()
start
end
is wrapped in a
statement that displays the output in the Output panel.
slice()
trace()
// Index values for the string literal
// positive index: 0 1 2 3 4
// string: L o r e m
// negative index: -5 -4 -3 -2 -1
var my_str:String = "Lorem";
// slice the first character
trace("slice(0,1): "+my_str.slice(0, 1)); // output: slice(0,1): L
trace("slice(-5,1): "+my_str.slice(-5, 1)); // output: slice(-5,1): L
// slice the middle three characters
trace("slice(1,4): "+my_str.slice(1, 4)); // slice(1,4): ore
trace("slice(1,-1): "+my_str.slice(1, -1)); // slice(1,-1): ore
// slices that return empty strings because start is not to the left of end
634
ActionScript classes

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE and is the answer not in the manual?

Table of Contents