A brief talk on the String object processing _javascript techniques encountered in JavaScript

Source: Internet
Author: User
Tags lowercase

To handle parameters in JavaScript:

<script>
function GetParam ()
{
urlinfo=window.location.href;//Get the URL of the current page
intlen= Urlinfo.length; Gets the length of the URL
offset=urlinfo.indexof ("?");//Set the position at which the parameter string begins
Strkeyvalue=urlinfo.substr (offset,len);//Fetch parameter string A string arrparam=strkeyvalue.split ("=") Like "id=1" is obtained here, and//the
argument string obtained is segmented according to "="
strparamvalue=arrparam[1]; Gets the parameter value
alert ("The parameter value you want to pass is" +strparamvalue);
}
</script>

Properties of string Strings objects in javascript:

length--returns the string length, not a function, and does not require parentheses.

prototype--Add properties and methods

There are some functions in JavaScript that handle string string objects:

Concat ()-combines the text of two or more characters to return a new string. (basically all are stitching themselves)

CharAt (a)-returns the character a at the specified position. (use less, but it feels very useful)

IndexOf (a)-returns the index of the first occurrence of a substring a in a string, or returns 1 if no match is made. (often used)

LastIndexOf (a)-returns the index of the last occurrence of a substring a in a string, or returns 1 if no match is made. (often used)

Match (REG)-checks whether a string matches a regular expression Reg. (is always very weak, seize the time to study well)

SUBSTRING (begin,end)-Returns a substring of a string with arguments containing both ends. (Note all lowercase)

SUBSTR (Start,length)-Returns a specified number of characters that are extracted from the start subscript from the string. (Don't confuse it with the one above)

Split (Separator,howmany)-separator is a string or regular expression (required), Howmany specifies the length of the array returned (optional)---commonly used

Replace (REGEXP/SUBSTR, replacement)-replacement character (very important)

toLowerCase () – Converts the entire string into lowercase letters.

toUpperCase () – Converts the entire string into uppercase letters.

The above JavaScript string object is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud habitat community.

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.