JavaScript strings are used to store and manipulate text

Source: Internet
Author: User
Tags locale

JavaScript strings are used to store and manipulate text

var string_value= ' DASFSDFSD ';

Note: strings are accurately positioned to take advantage of the index
var character=string_value[7];

Escape characters using quotation marks:

Escape single quotation marks
var answer = ' it\ ' s alright ';
Escape double Quotes
var answer = "He is called \" johnny\ "";

A backslash is an escape character. The escape character converts a special character to a string character:
The escape character () can be used to escape apostrophes, line breaks, quotation marks, and other special characters.
The following table lists special characters that can be escaped with escape characters in a string:
Code output-------------------------------------------------------
\ ' Single quotation mark
\ "Double quotation marks
\ \ counter Slash
\ nthe line break
\ r Enter
\ttab (tab)
\b Backspace
\f Page Break


#注意: Do not create a String object. It slows down execution speed and may have other side effects:
var x = "John";
var y = new String ("John");
(x = = y)//is false because X is a string and Y are an object.

String properties and Methods------------------------------------------------------------------------------

Raw value strings, such as "John", have no properties and methods (because they are not objects).
Raw values can use JavaScript properties and methods, because JavaScript can take raw values as objects when executing methods and properties.
The string method is described in the next section.
String properties

Property Description
Constructor returns a function that creates a string property
Length returns the lengths of the strings
Prototype allows you to add properties and methods to an object

String method

Method description
CharAt () returns the character at the specified index position
charCodeAt () returns the Unicode value of the specified index position character
Concat () joins two or more strings, returning the concatenated string
fromCharCode () converts a character to a Unicode value
IndexOf () returns the position of the first occurrence of the specified character in a string
LastIndexOf () returns the position of the last occurrence of the specified character in a string
Localecompare () compares two strings in a local-specific order
Match () finds the matching of one or more regular expressions
Replace () replaces a substring that matches a regular expression
Search () Retrieves a value that matches a regular expression
Slice () extracts a fragment of a string and returns the extracted part in a new string
Split () splits a string into a substring array
SUBSTR () extracts a specified number of characters from the starting index number in a string
SUBSTRING () extracts the characters between two specified index numbers in a string
toLocaleLowerCase () Converts a string to lowercase based on the host's locale, with only a few languages (such as Turkish) with a local case-specific mapping
toLocaleUpperCase () Converts a string to uppercase based on the host's locale, with only a few languages (such as Turkish) with a local case-specific mapping
toLowerCase () Converts a string to lowercase
ToString () returns the String object value
toUpperCase () Converts a string to uppercase
Trim () Remove string end and end blanks
ValueOf () returns the original value of a string object
Related articles

JavaScript Standard Reference manual: JavaScript string Object

JavaScript strings are used to store and manipulate text

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.