Article Introduction: JS Built-in features one: string concatenation. |
JS built-in features one: string connection;
If the plus (+) operator is used for numbers, the addition of two numbers is added;
However, by acting on a string, it means that the string is connected and the second string is concatenated after the first.
var a = "Hello,"; var B = "World";
var s = a + B; Generate string "Hello,world";
alert (s);//Display a string
alert (s.length);//The length of the display string
String other method of invocation:
S.charat (0); First character: "H"
S.charat (s.length-1); Last string "D"
S.substring (1,4); 2nd to 4th string Note is not the 2nd to 5th string "ell";
S.slice (1,4); Ditto "ell";
S.replace ("H", "H"); "H" replaces "H", full character replacement,
S.touppercase (); Full-text capitalization
S.slice (-3); The last three characters "Rld";
S.indexof ("L"); The position of the first appearance of the character L; "2"
S.lastindexof ("L"); Position of the last occurrence of the character L; "10"
S.indexof ("L", 3); The first occurrence of the string at position 33 and after "3"
S.split (","); ["Hello", "World"] split into substrings
Note: string can not be subtracted, can only intercept part of the string addition "+";