JavaScript Learning Tutorial: string concatenation

Source: Internet
Author: User
Tags string split

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 "+";



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.