Simple learning of String objects in JavaScript

Source: Internet
Author: User

11th Lesson
String Object Introduction
1: Properties
in JavaScript, you can use single quotes, or one character enclosed in double quotation marks, as
an instance of a character object, so you can add it after a string. To invoke String
the properties and methods of the object.
    
For example
long returns the length of the string object, which represents the number of characters in the string.
"Hello, everyone." The length of the length;//string is 3, and each man represents a character
    
2: Common methods
indexOf (Substring[,startindex])
used to return the character position of the first occurrence of a substring, if no specified
the string, then returns-1;
substring: Required parameter, substring to find in string object
startIndex: Optional parameter, starting from the specified position to find
cases are as follows
        

123<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">4<title> methods for calling functions 1</title>5<script language= "JavaScript" >6         varstr= "Hello World";7         varStr_length=str.indexof ("O", 3);8 alert (str_length);9</script>Ten One<body> A      -</body> -


substr (Start[,length])
A string that is used to return the specified strings.
start: A required parameter that specifies the starting subscript to get the substring. If a
is a negative number, the starting position is calculated from the tail of the string. -1 represents the last character
-2 for the second-to-last character, etc.
Length: Optional parameter that specifies the number of characters in the string, if omitted
, the substring from the start position of the start to the end of the string is returned.
cases are as follows

123<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">4<title> methods for calling functions 1</title>5<script language= "JavaScript" >6         varA= "Hello World";7         varSubs=a.substr (4,7);8 alert (subs);9</script>Ten One<body> A      -</body> -


SUBSTRING (From[,to])
From: Used to specify the position of the first character to get the substring in a string
To: optional parameter, specifying the last position
[From,to] Open after closed, contains from, does not contain to, so if you want to get to the
characters, need to+1;
cases are as follows

123<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">4<title> methods for calling functions 1</title>5<script language= "JavaScript" >6         varA= "Hello World";7         varSubs=a.substring (6,11);8 alert (subs);9</script>Ten One<body> A      -</body> -

    split (Delimiter[,limit])
         Used to split a string into an array of strings
         delimiter: The specified delimiter
        limit: Optional parameter that specifies the maximum length of the returned array.
         Return value: An array of strings
         
         cases are as follows
     

123<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">4<title> methods for calling functions 1</title>5<script language= "JavaScript" >6         varA= "Hello.world";7         varArr=a.split (".");8          for(vari=0;i<arr.length;i++){9 alert (arr[i]);Ten         } One</script> A -<body> -      the</body> -


Simple learning of String objects in JavaScript

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.