JS Basic Review---string manipulation

Source: Internet
Author: User

var str= "Hello World";
1 charAt () returns the first few subscript characters of a string
Console.log (Str.charat (4));
2:fixed () displaying strings in typewriter font
document.write (Str.fixed ());
3:indexof () returns the position of the first occurrence of a character or string fragment in the string, and returns 1 if it does not exist.
Console.log (Str.indexof ("w"));
Console.log (Str.indexof ("pp"))
4: Convert strings to uppercase and lowercase
Console.log (Str.touppercase ())//Uppercase
Console.log (Str.tolowercase ())//lowercase
The 5:substring (Star,stop) method is used to extract the character of a string intermediary between two specified subscripts.
A new string value that contains a substring of stringobject whose contents are all characters from start to stop-1, with a length of stop minus start

Console.log (Str.substring (4))//Starting with the 4th subscript, to the end of the string
Console.log (str.substring (2,5))//return subscript 2 to subscript 4 characters
6: Display the string as a subscript
document.write (Str.sup ())//superscript
document.write (Str.sub ())//subscript
7: Display string as Strikethrough
document.write (Str.strike ());
8:split, dividing a string into an array
Console.log (Str.split (""));
["Hello", "World"]
9 Slice (star,end), extracting a string fragment
Includes the string Stringobject all characters from start (including start) to end (not including end). Star is allowed to take negative numbers, and a negative number is calculated from the end
document.write (Str.slice (3,6))
Ten replace (A, a, a) is a regular rule that matches a string, and B is a string that needs to be replaced
Console.log (Str.replace (/hello/, "fuckb"));

JS Basic Review---string manipulation

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.