substr() and substring() methods

substr() and substring() methods - Copy a substring of a string The

    substr() and substring() methods can be used to extract a substring from a string and assign it to another variable, or in an expression, which Both methods return the same result, both substrings, but they require different parameters.
    The substring() method accepts two parameters: the start position of the substring and the character position after the last character in the substring. The second parameter is optional. If it is not included, the substring contains from the start position to the end of the string of all characters.
    For example, if the string is "JavaScript", to extract the substring "Java", you can use the substring() method, as follows:
    var mySrting = "JavaScript";
    var mySubString = mySting.substring (0.4);
    alert(mySubString);

    Similar to the substring() method, the substr() method also takes two parameters. The first argument is the starting position of the string to be included in the substring. However, the second is the length of the substring to be extracted from the string. E.g. The above code can be rewritten as:
    var myString = "JavaScript";
    var mySubString = myString.substr(0,4);
    alert(mySubString);

    Similar to the substring() method, the second parameter of the substr() method is optional, if it is not included, the substring contains all characters from the start position to the end of the string.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326641667&siteId=291194637