String.slice()
415
String.slice()
Availability
Flash Player 5.
Usage
my_str
.slice(
start:Number
, [
end:Number
])
: String
Parameters
start
A number; the zero-based index of the starting point for the slice. If
start
is a negative
number, the starting point is determined from the end of the string, where -1 is the last character.
end
A number; an integer that is 1+ the index of the ending point for the slice. The character
indexed by the
end
parameter is not included in the extracted string. If this parameter is omitted,
String.length
is used. If
end
is a negative number, the ending point is determined by counting
back from the end of the string, where -1 is the last character.
Returns
A string; a substring of the specified string.
Description
Method; returns a string that includes the
start
character and all characters up to, but not
including, the
end
character. The original String object is not modified. If the
end
parameter is
not specified, the end of the substring is the end of the string. If the character indexed by
start
is
the same as or to the right of the character indexed by
end
, the method returns an empty string.
Example
The following example creates a variable,
my_str,
assigns it a String value, and then calls the
slice()
method using a variety of values for both the
start
and
end
parameters.
Each call to
the slice()
method is wrapped in a
trace()
statement that sends the output to the log file.
// 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
trace("slice(1,1): "+my_str.slice(1, 1)); // slice(1,1):
trace("slice(3,2): "+my_str.slice(3, 2)); // slice(3,2):
trace("slice(-2,2): "+my_str.slice(-2, 2)); // slice(-2,2):
Содержание FLEX-FLEX ACTIONSCRIPT LANGUAGE
Страница 1: ...Flex ActionScript Language Reference...
Страница 8: ......
Страница 66: ...66 Chapter 2 Creating Custom Classes with ActionScript 2 0...
Страница 76: ......
Страница 133: ...break 133 See also for for in do while while switch case continue throw try catch finally...
Страница 135: ...case 135 See also break default strict equality switch...
Страница 146: ...146 Chapter 5 ActionScript Core Language Elements See also break continue while...
Страница 229: ...while 229 i 3 The following result is written to the log file 0 3 6 9 12 15 18 See also do while continue for for in...
Страница 808: ...808 Chapter 7 ActionScript for Flash...
Страница 810: ...810 Appendix A Deprecated Flash 4 operators...
Страница 815: ...Other keys 815 Num Lock 144 186 187 _ 189 191 192 219 220 221 222 Key Key code...
Страница 816: ...816 Appendix B Keyboard Keys and Key Code Values...
Страница 822: ...822 Index...