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

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

Starter Package

SSD Cloud server and data transfer for only $2.50 a month

Get Started >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.