Home >Web Front-end >JS Tutorial >Common string methods in JS
Commonly used string methods in JS (recommended)
<SPAN style="FONT-FAMILY: 'courier new', courier">var str01 = "odd open xboxone" , str02 = "hey"; var str03; var num = 15; </SPAN>
// The first half of " str01. " is omitted below (this part is not this)
charAt(num) // Get the single character at the specified index position
charCodeAt(num) // Get the Unicode value of the character at the specified index position (ascii is its subset)
concat(str01,str02) //Concatenate two characters~
indexOf("str") //Get the index of the first occurrence of str
lastIndexOf( "str") // Get the index of the last occurrence of str
replace( "oldStr" , "newStr" ) // Find oldStr and replace it with newStr
slice( start, end) // The object can be a string or an array, remember that its range does not include end
substr( start, length) // Take length characters starting from the index start, and the length cannot be less than 0 otherwise returns an empty string
search("str") // Search for the string "str" in str01 and return the index of its first character in str01
String.fromCharCode(uniNum,uniNum) //The parameter is a Unicode value (>=1 is enough)
str01.localeCompare(str02) //Compare based on local specific rules, if str01>str02 = 1, otherwise -1 is equal to 0
str03 = str02.valueOf(); // The original value of the string object (str02) can be returned
str03 = str01.split( "str") // Split the original string into an array object, the delimiter is a comma, and the parameter is an empty space string
var n = num.toString() // Change the Number object = >String object (n is a character), the source object has not changed
// The following is the basic style class
1f504ca5f9d4d3c8bece03e58ed42506var txt = "heyguy"0fe0b7695b8025b8365ca0c050e039db
txt.link("url") // Convert to hyperlink, remember to add http://
txt.big() // Can be changed to big/small/bold/italic/fixed/sub/sup/strike (strike is to delete the line)
txt. fontcolr("red") // name/rgb/#000000 is still the same old routine
txt.fontsize(num) //Only supports numbers
The above is the editor This brings you all the content of common JS string methods (recommended). I hope you will support the PHP Chinese website~
For more articles related to JS common string methods, please pay attention to the PHP Chinese website!