Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the methods of string objects in JavaScript

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the methods of string objects in JavaScript, which are very detailed and have certain reference value. Friends who are interested must finish reading them.

The methods of JavaScript string objects are: anchor (), big (), blink (), bold (), charAt (), concat (), fixed (), indexOf (), lastIndexOf (), replace (), search (), and so on.

The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.

The JavaScript String object is used to process strings, which provides a number of methods for manipulating strings, as well as some properties.

The syntax format for creating a String object is as follows:

Var val = new String (value); var val = String (value)

Where the parameter value is the string or string object to be created.

In JavaScript, strings and string objects can be converted freely, so whether you are creating a string object or directly declaring a variable of a string type, you can directly use the methods and properties provided in the string object.

The method of JavaScript string object

The following table lists the methods provided in the String object and their description information:

Method describes anchor () to create a HTML anchor, that is, to generate a label The name property of the tag is the parameter big () in the anchor () method. Display the flashing string bold () using the large font display string blink (). Use the bold display string charAt () to return the character charCodeAt () at the specified position. Return the Unicode encoding concat () splicing string fixed () for the specified character. Typewriter text display string fontcolor () displays the string fontsize () in the specified color. Use the specified size to display the string fromCharCode () to convert the character encoding to a string indexOf () to retrieve the string Get the first occurrence position of a given string in the string object italics () use the italic display string lastIndexOf () to get the last occurrence of the given string in the string object link () displays the string as a link localeCompare () returns a number And use this number to indicate whether the string object is greater than, less than or equal to the given string match () according to the character replace () in the regular expression matching string to replace the substring search () that matches the regular expression to get the fragment of the string that matches the position where the string first appears slice () And return it to small () use a small font to display the string split () split the string into an array of strings based on a given character strike () use delete lines to display the string sub () display the string as subscript substr () intercept the string substring () of specified length from the specified index position intercept the character sup () between two specified indexes in the string and display the string as superscript toLocaleLowerCase () convert a string to lowercase toLocaleUpperCase () convert a string to uppercase toLowerCase () convert a string to lowercase toUpperCase () convert a string to uppercase toString () return the string valueOf () returns the original value of a string object

The sample code is as follows:

Var str = new String ('JavaScript tutorial'); [xss_clean] (str.anchor ("myanchor") + "

"); / / generate a HTML code: JavaScript tutorial [xss_clean] (str.big () +"

"); / / generate a HTML code: JavaScript tutorial [xss_clean] (str.blink () +"

"); / / generate a HTML code: JavaScript tutorial [xss_clean] (str.bold () +"

"); / / generate a HTML code: JavaScript tutorial [xss_clean] (str.charAt (10) +"

"); / / get the 11th character in str, output: teach [xss_clean] (str.charCodeAt (10) +"

"); / / get the Unicode encoding of the 11th character in str, output: 25945 [xss_clean] (str.concat (" String object ") +"

Concatenate the string "String object" after the string str, output: JavaScript tutorial String object [xss_clean] (str.fixed () + "

"); / / generate a HTML code: JavaScript tutorial [xss_clean] (str.fontcolor (" red ") +"

"); / / generate a HTML code: JavaScript tutorial [xss_clean] (str.fontsize (2) +"

"); / / generate a piece of HTML code: JavaScript tutorial [xss_clean] (String.fromCharCode (72 and 69)) +"

"); / / convert Unicode encoding to specific characters, output: Hello [XSS _ clean] (str.indexOf (" Script ") +"

"); / / get the string" Script "that appears for the first time in str, output: 4 [xss_clean] (str.italics () +"

); / / generate a HTML code: JavaScript tutorial [xss_clean] (str.lastIndexOf ("a") + "

"); / / get the last occurrence of the string" a "in str, and output 3 [xss_clean] (str.link (" http://c.biancheng.net/") + ")

"); / / generate a HTML code: JavaScript tutorial [xss_clean] (str.localeCompare (" JavaScript ") +"

"); / / compare the string object with the given string. Return: 1 [xss_clean] (str.match (/ [abc] / g) +"

"); / / retrieve str according to regular / [abc] / g, and return: a str a, c [XSS _ clean] (str.replace (/ [abc] / g," Y ") +"

Replace regular / [abc] / g matching characters with the string "Y". Return: JYvYSYript tutorial [xss_clean] (str.search (/ [Script] / g) + "

"); / / gets the first occurrence position of the string that matches the rule, and returns: 4 [xss_clean] (str.slice (6jue 11) +"

"); / / intercept the string (get the 7th to 11th characters in str), and return: ript teaches [xss_clean] (str.small () +"

); / / generate a HTML code: JavaScript tutorial [xss_clean] (str.split ("a") + "

"); / / split the string str into an array according to" a ", and return: [xss_clean] (str.strike () +"

"); / / generate a HTML code: JavaScript tutorial [xss_clean] (str.sub () +"

"); / / generate a piece of HTML code: JavaScript tutorial [xss_clean] (str.substr (3,7) +"

"); / / start with the 4th character, intercept 7 characters backwards, and return: ascript [XSS _ clean] (str.substring (3,7) +"

"); / / intercept the string (get the 4th to 7th characters in str), and return: ASCR [XSS _ clean] (str.sup () +"

"); / / generate a HTML code: JavaScript tutorial [xss_clean] (str.toLocaleLowerCase () +"

"); / / return: javascript tutorial [xss_clean] (str.toLocaleUpperCase () +"

"); / / return: JAVASCRIPT tutorial [xss_clean] (str.toLowerCase () +"

"); / / return: javascript tutorial [xss_clean] (str.toUpperCase () +"

"); / / return: JAVASCRIPT tutorial [xss_clean] (str.toString () +"

"); / / return: JavaScript tutorial [xss_clean] (str.valueOf () +"

"); / / return: JavaScript tutorial above is all the content of this article" what are the methods of string objects in JavaScript? "Thank you for reading! hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report