What are the methods of JavaScript string objects?
The methods of JavaScript string objects are: anchor(), big(), blink(), bold(), charAt(), concat(), fixed(), indexOf(), lastIndexOf(), replace(), search(), etc.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
JavaScript String object is used to process strings, which provides a large 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);
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 string type, you can directly use the methods and properties provided in the string object. .
Methods of JavaScript string objects
The following table lists the methods and description information provided in the String object:
Method | Description |
---|---|
anchor() | Creates an HTML anchor, that is, generates a <a> Label, the name attribute of the label is the parameter in the anchor() method |
Display the string in large font | |
Display the flashing string | |
Use bold to display the string | |
Returns the character at the specified position | |
Returns the specified character Unicode encoding | |
Concatenate strings | |
to typewriter Text display string | |
Use the specified color to display the string | |
Use the specified size to display the string | |
Convert the character encoding to a string | |
Retrieve a string and get the position where the given string first appears in the string object | |
Use italics to display the string | |
Get the last occurrence position of the given string in the string object | |
Display a string as a link | |
Returns a number and uses that number to represent the character Whether the string object is greater than, less than, or equal to the given string | |
Match characters in the string according to the regular expression | |
Replace the substring matching the regular expression | |
Get the substring matching the regular expression The position where the matching string first appears | |
Intercepts the fragment of the string and returns it | |
Use small font size to display the string | |
Split the string into a string array based on the given characters | |
Use strikethrough to display string | |
The string is displayed as a subscript | |
Intercept the string of the specified length from the specified index position | |
Intercept the characters between two specified indexes in the string | |
Display the string as a superscript | |
Convert the string to lowercase | |
Convert the string Convert to uppercase | |
Convert the string to lowercase | |
Convert the string to uppercase | |
Return the string | |
Return the original value of a string object |
var str = new String('JavaScript教程'); document.write(str.anchor("myanchor") + "<br>"); // 生成一段 HTML 代码:<a name="myanchor">JavaScript教程</a> document.write(str.big() + "<br>"); // 生成一段 HTML 代码:<big>JavaScript教程</big> document.write(str.blink() + "<br>"); // 生成一段 HTML 代码:<blink>JavaScript教程</blink> document.write(str.bold() + "<br>"); // 生成一段 HTML 代码:<b>JavaScript教程</b> document.write(str.charAt(10) + "<br>"); // 获取 str 中的第 11 个字符,输出:教 document.write(str.charCodeAt(10) + "<br>"); // 获取 str 中第 11 个字符的 Unicode 编码,输出:25945 document.write(str.concat(" String 对象") + "<br>"); // 将字符串“ String 对象”拼接到字符串 str 之后,输出:JavaScript教程 String 对象 document.write(str.fixed() + "<br>"); // 生成一段 HTML 代码:<tt>JavaScript教程</tt> document.write(str.fontcolor("red") + "<br>"); // 生成一段 HTML 代码:<font color="red">JavaScript教程</font> document.write(str.fontsize(2) + "<br>"); // 生成一段 HTML 代码:<font size="2">JavaScript教程</font> document.write(String.fromCharCode(72,69,76,76,79) + "<br>"); // 将 Unicode 编码转换为具体的字符,输出:HELLO document.write(str.indexOf("Script") + "<br>"); // 获取字符串“Script”在 str 中首次出现的为,输出:4 document.write(str.italics() + "<br>"); // 生成一段 HTML 代码:<i>JavaScript教程</i> document.write(str.lastIndexOf("a") + "<br>"); // 获取字符串“a”在 str 中最后一次出现的位置,输出 3 document.write(str.link("http://c.biancheng.net/") + "<br>"); // 生成一段 HTML 代码:<a href="http://c.biancheng.net/">JavaScript教程</a> document.write(str.localeCompare("JavaScript") + "<br>"); // 比较字符串对象与给定字符串,返回:1 document.write(str.match(/[abc]/g) + "<br>"); // 根据正则 /[abc]/g 检索 str,返回:a,a,c document.write(str.replace(/[abc]/g, "Y") + "<br>"); // 使用字符串“Y”替换正则 /[abc]/g 匹配的字符,返回:JYvYSYript教程 document.write(str.search(/[Script]/g) + "<br>"); // 获取与正则匹配的字符串首次出现的位置,返回:4 document.write(str.slice(6,11) + "<br>"); // 截取字符串(获取 str 中第 7 到第 11 个字符),返回:ript教 document.write(str.small() + "<br>"); // 生成一段 HTML 代码:<small>JavaScript教程</small> document.write(str.split("a") + "<br>"); // 根据“a”将字符串 str 拆分为数组,返回:J,v,Script教程 document.write(str.strike() + "<br>"); // 生成一段 HTML 代码:<strike>JavaScript教程</strike> document.write(str.sub() + "<br>"); // 生成一段 HTML 代码:<sub>JavaScript教程</sub> document.write(str.substr(3, 7) + "<br>"); // 从第 4 个字符开始,向后截取 7 个字符,返回:aScript document.write(str.substring(3, 7) + "<br>"); // 截取字符串(获取 str 中第 4 到第 7 个字符),返回:aScr document.write(str.sup() + "<br>"); // 生成一段 HTML 代码:<sup>JavaScript教程</sup> document.write(str.toLocaleLowerCase() + "<br>"); // 返回:javascript教程 document.write(str.toLocaleUpperCase() + "<br>"); // 返回:JAVASCRIPT教程 document.write(str.toLowerCase() + "<br>"); // 返回:javascript教程 document.write(str.toUpperCase() + "<br>"); // 返回:JAVASCRIPT教程 document.write(str.toString() + "<br>"); // 返回:JavaScript教程 document.write(str.valueOf() + "<br>"); // 返回:JavaScript教程
[Related recommendations:
javascript learning tutorialThe above is the detailed content of What are the methods of JavaScript string objects?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

Usage: In JavaScript, the insertBefore() method is used to insert a new node in the DOM tree. This method requires two parameters: the new node to be inserted and the reference node (that is, the node where the new node will be inserted).

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

There are no traditional classes and objects in Go language, but structs and methods are used. Class methods are bound to the type and are used to operate on the entire type. Object methods are bound to object instances and are used to operate on a specific instance. The receivers of the two are different: the receiver of class methods is the type, while the receiver of object methods is the object instance pointer. There are also differences in naming conventions: class methods start with a capital letter, and object methods start with a lower case letter.
