JavaScript String handling of of String objects

  • 2020-03-30 04:08:12
  • OfStack

Define a String object

The JavaScript String object is used to process text strings. The syntax for creating a String object is as follows:


<script language="JavaScript">
var str_object = new String( str );
var str1 = String( str );
var str2 = str;
</script>

Of the three methods above, only the first one USES the String constructor to strictly define a String object and return an object (object). The second is to call the String function, which returns the conversion parameter STR as the original String String. The third is to define a string variable, but still treat it as a string object in JavaScript.

To see the difference, run the following statement:


alert( typeof str_object ); //The output object < br / > alert( typeof str1 );  //The output string < br / > alert( typeof str2 );  //The output string < br / >

String object properties

attribute describe
constructor A reference to the function that created the object
length Length of string
prototype Add properties and methods to the object

String object method

The list of common methods of String object is as follows:

String output

(link: #) : message warning box output text
(link: #) : outputs text to a Web page

String manipulation

(link: #) : concatenates two or more strings
(link: #) : string replacement or regular matching replacement
(link: #) : intercepts a string by specifying the start and end positions
(link: #) : splits a string into an array of strings
(link: #) : intercepts a string based on the starting position and length
(link: #) : intercepts a string by specifying the start and end positions

String conversion

(link: #) : converts the string to lowercase
(link: #) : converts the string to uppercase
(link: #) : converts one or more Unicode values to strings

String lookup

(link: #) : gets the character in the specified position
Gets the Unicode encoding for the specified position character
(link: #) : computes the first occurrence of a specified string in a string
(link: #) : computes the first occurrence of a specified string in a string

HTML tags class

(link: #) : gets the character in the specified position
(link: #) : displays the string in the specified color
(link: #) : displays the string to the specified size
(link: #) : displays the string in italics
(link: #) : adds a hyperlink to a string
(link: #) : add a delete line to the string
(link: #) : displays a string as a subscript
(link: #) : displays a string as a superscript


Related articles: