JScript Methods (Windows Sc ...


JScript
slice Method (String) (Windows Scripting - JScript)

Updated: March 2009

Returns a section of a string.

stringObj.slice(start, [end]) 
Arguments

stringObj

Required. A String object or literal.

start

Required. The index to the beginning of the specified portion of stringObj.

end

Optional. The index to the end of the specified portion of stringObj. The substring includes the characters up to, but not including, the character indicated by end. If this value is not specified, the substring continues to the end of stringObj.

Remarks

The slice method returns a String object containing the specified portion of stringObj.

The slice method copies up to, but not including, the character indicated by end.

If start is negative, it is treated as length + start where length is the length of the string. If end is negative, it is treated as length + end where length is the length of the string. If end is omitted, extraction continues to the end of stringObj. If end occurs before start, no characters are copied to the new string.

Example

In the first example, the slice method returns the entire string. In the second example, the slice method returns the entire string, except for the last character.

str1.slice(0)
str2.slice(0,-1)
Requirements

Version 3

Applies To: String Object (Windows Scripting - JScript)

See Also

Reference

Change History

Date

History

Reason

March 2009

Corrected information about the end argument.

Content bug fix.

Tags :


Page view tracker