Get the App
SLTechnology News&Howtos  ›  Development  › 

How does JavaScript deal with existing character blocks

Shulou Source: shulou.com Published: 2022-06-01 13:35:55 10月30日 Update

This article mainly shows you "JavaScript how to deal with existing character blocks", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "JavaScript how to deal with existing character blocks" this article.

JavaScript string object

The JavaScript String (string) object is used to process existing character blocks.

Properties and description of String object

Constructor: a reference to the function that created the object

Length: length of the string

Prototype: allows you to add properties and methods to objects

String object method and description

Anchor () / / create a HTML anchor. Big () / / displays the string in a large font. Blink () / / displays the flashing string. Bold () / / displays the string in bold. CharAt () / / returns the character at the specified position. CharCodeAt () / / returns the Unicode encoding of the character at the specified position. Concat () / / connection string. Fixed () / / displays the string as typewriter text. Fontcolor () / / displays the string using the specified color. Fontsize () / / displays the string using the specified size. FromCharCode () / / creates a string from character encoding. IndexOf () / / retrieves the string. Italics () / / displays the string in italics. LastIndexOf () / / searches for strings from back to front. Link () / / displays the string as a link. LocaleCompare () / / compares two strings in a local-specific order. Match () / / finds a match for one or more regular expressions. Replace () / / replaces the substring that matches the regular expression. Search () / / retrieves the value that matches the regular expression. Slice () / / extracts a fragment of the string and returns the extracted part in the new string. Small () / / uses small font sizes to display strings. Split () / / splits the string into an array of strings. Strike () / / uses the delete line to display the string. Sub () / / displays the string as a subscript. Substr () / / extracts a specified number of characters from the string from the starting index number. Substring () / / extracts the character between two specified index numbers in the string. Sup () / / displays the string as superscript. ToLocaleLowerCase () / / converts the string to lowercase. ToLocaleUpperCase () / / converts the string to uppercase. ToLowerCase () / / converts the string to lowercase. ToUpperCase () / / converts the string to uppercase. ToSource () / / represents the source code of the object. ToString () / / returns a string. ValueOf () / / returns the original value of a string object.

Use the length property to calculate the length of the string:

Var txt= "Hello World!" [xss_clean] (txt.length)

Add a style to the string:

Var txt= "Hello World!" [xss_clean] ("

Big: "+ txt.big () +"

") [xss_clean] ("

Small: "+ txt.small () +"

") [xss_clean] ("

Bold: "+ txt.bold () +"

") [xss_clean] ("

Italic: "+ txt.italics () +"

") [xss_clean] ("

Blink: "+ txt.blink () +" (does not work in IE)

") [xss_clean] ("

Fixed: "+ txt.fixed () +"

") [xss_clean] ("

Strike: "+ txt.strike () +"

") [xss_clean] ("

Fontcolor: "+ txt.fontcolor (" Red ") +"

") [xss_clean] ("

Fontsize: "+ txt.fontsize (16) +"

") [xss_clean] ("

Lowercase: "+ txt.toLowerCase () +"

") [xss_clean] ("

Uppercase: "+ txt.toUpperCase () +"

") [xss_clean] ("

Subscript: "+ txt.sub () +"

") [xss_clean] ("

Superscript: "+ txt.sup () +"

") [xss_clean] ("

Link: "+ txt.link (".. ") +"

")

IndexOf () method:

Var str= "Hello world!" [xss_clean] (str.indexOf ("Hello") + ") [xss_clean] (str.indexOf (" World ") +") [xss_clean] (str.indexOf ("world"))

Note: use indexOf () to locate the first occurrence of a specified character in a string.

Match () method:

Var str= "Hello world!" [xss_clean] (str.match ("world") + ") [xss_clean] (str.match (" World ") +") [xss_clean] (str.match ("worlld") + ") [xss_clean] (str.match (" world! "))

Note: use match () to find a specific character in a string and return that character if found.

Replace the character in the string-replace ():

Var str= "Visit Microsoft!" [xss_clean] (str.replace (/ Microsoft/, "HuluMiao"))

Note: use the replace () method to replace some characters in a string with others.

The above is all the content of the article "how to deal with existing character blocks in JavaScript". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Character string object method position content property regular comment article expression length two uppercase lowercase index index number encoding learning help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Huawei OPPO Reno Docker Xiaomi