String is an indispensable element in JavaScript programming, and mastering the common method of string is also the only way in our learning process, we summarize some of the most common string methods.
String.charat (postion)
The Charat method returns the character at the position position in string. Returns an empty string if position is less than 0 or greater than the length of the string. Because JS does not have a character type, the return is still a string
var name= "Deng";
var a=name.charat (1);
document.write (a);
Tring.concat (String ...)
The Concat method joins the other strings together to construct a new string. Consistent with the "+" role
var name= "Deng";
var a=name.concat ("1", "@2");
document.write (a);
String.IndexOf (searchstring,position)
The IndexOf method finds another string. If it is found, returns the position of the first matching character, or returns-1. optional parameter position can be set to start a lookup from a specified location. For example, to determine whether a label contains a specified class name.
var classname= "Calss1 class2 class3";
var a=classname.indexof ("Class2");
document.write (a);
String.Replace (Serachvalue,replacevalue)
The Replace method finds and replaces a string and returns a new string. A parameter searchvalue is a string (or a regular expression) that is replaced only where it first appears.
var name= "deng,kun,ming";
var a=name.replace (",", "_");
document.write (a);
String.slice (Start,end)
The slice method copies a portion of a string to construct a new string that is equal to the length of End-start.
var name= "deng,kun,ming";
var a=name.slice (2,5);
document.write (a);
String.Split (Separtor,limit)
The Split method splits the string into fragments to create an array of strings. Optional parameter limit can limit the number of fragments that are fragmented. If separator is a null character, it returns an array of single characters, which is often used when you need to convert a character to an array.
var name= "dengkunming";
var a=name.split ("");
document.write (a);
This method finds all occurrences of separator in string
var name= "129.168.0.1"; var a=name.split ("."); document.write (a);
String.substring (Start,end)
The substring method gets the substring of the string. function as slice.
var name= "129.168.0.1";
var a=name.substring (2,5);
document.write (a);
String.tolowercase ()
The toLowerCase method returns a new string, which is converted to lowercase format. This is often used when judging labels
var name= "DIV SPAN";
var a=name.tolowercase ();
document.write (a);