3. Getting Started Lesson 3: String operations

Source: Internet
Author: User

Because String is the most commonly used data type in our development, we need to know it well.

1. Creation method:

1) Basic Type: var s = "abc ";

2) object type: var s = new String ("abc ");

2, the common method: From the http://www.w3school.com.cn/js/jsref_obj_string.asp)

Method Description FF IE
CharAt () Returns the characters at the specified position. 1 3
CharCodeAt () Returns the Unicode encoding of characters at the specified position. 1 4
FromCharCode () Creates a string from the character encoding. 1 4
IndexOf () Returns a string. 1 3
LastIndexOf () Search for strings from the back and forward. 1 3
LocaleCompare () Compares two strings in a specific local order. 1 4
Match () Find the matching of one or more regular expressions. 1 4
Replace () Replace the substring that matches the regular expression. 1 4
Search () Returns the value that matches the regular expression. 1 4
Slice () Extract the string segment and return the extracted part in the new string. 1 4
Split () Splits a string into a string array. 1 4
Substr () Extracts a specified number of characters from the start index number. 1 4
Substring () Extract the characters between two specified index numbers in the string. 1 3
ToLocaleLowerCase () Converts a string to lowercase. - -
ToLocaleUpperCase () Converts a string to uppercase. - -
ToLowerCase () Converts a string to lowercase. 1 3
ToUpperCase () Converts a string to uppercase. 1 3
ValueOf () Returns the original value of a string object.

3. URI encoding:

When we fill out the form in the browser and submit it to the server, the browser will automatically encode the submission in the URI format. If the data to be submitted is as follows: http://www.johnyu.com/login.do? Uname = John & psd = 123 at this time the browser will automatically send the data http://www.johnyu.com/login.do in the following form? Uname = % E7 % BA % A6 % E7 % BF % B0 & psd = 123 indicates "? "Subsequent non-letters, numbers, including Chinese characters,", ', \, and spaces are encoded.

But when we use javascript to obtain the form data, and do not prepare to use the form for submission, we will not allow the browser to encode), such as ajax submission, we will face difficulties. In this case, we can use encodeURI (url:

Var s = "http://www.johnyu.com/login.do? Uname = John & psd = 123 "; var s1 = encodeURIComponent (s); document. write (s1 );

At this time, s1 is the Character Sequence processed by the URI!

This article from the "Yu yu" blog, please be sure to keep this source http://johnyu.blog.51cto.com/7838287/1299875

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.