Javascript [Electronic resources] : The Definitive Guide (4th Edition) نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Javascript [Electronic resources] : The Definitive Guide (4th Edition) - نسخه متنی

David Flanagan

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید


Availability


JavaScript 1.2; JScript 3.0; deprecated


Synopsis

string.substr(start, length)

Arguments


start

The start position of the substring. If this argument is negative, it
specifies a position measured from the end of the string: -1
specifies the last character, -2 specifies the second-to-last
character, and so on.

length

The number of characters in the substring. If this argument is
omitted, the returned substring includes all characters from the
starting position to the end of the string.


Returns


A copy of the portion of string starting
at and including the character specified by
start and continuing for
length characters, or to the end of the
string if length is not specified.


Description


substr( ) extracts and returns a substring of
string. It does not modify
string.

Note that substr( ) specifies the desired
substring with a character position and a length. This provides a
useful alternative to String.substring( ) and
String.splice( ), which specify a substring with
two character positions. Note, however, that this method has not been
standardized by ECMAScript and is therefore deprecated.


Example


var s = "abcdefg";
s.substr(2,2); // Returns "cd"
s.substr(3); // Returns "defg"
s.substr(-3,2); // Should return "ef"; returns "ab" in IE 4


Bugs


Negative values for start do not work in
JScript 3.0 (IE 4). Instead of specifying a character position
measured from the end of the string, they specify character position
0.


See Also


String.slice( ), String.substring( )

/ 844