1. Character Method:
Str.charat (): can access a specific character in a string, can accept a number of 0 to a string length-1 as a parameter, return the character under that position, if the argument exceeds the range, returns an empty string, if there is no argument, returns the position of 0 characters;
Str.charcodeat (): As with Charat () usage, the difference is that charCodeAt () returns a character encoding instead of a character.
var anystring= "Hello Tino"; Anystring.charat () //"H"Anystring.charat (2) // "L"Anystring.charat (+) //""
2. String manipulation methods:
string concatenation:
The most common is the string concatenation, you can use the "+" operator to connect two strings, or use the concat () method, the Concat () method to accept one or more string parameters, return the concatenation of the resulting new string, it should be noted that the concat () method does not change the value of the original string.
var str= "Hello Tino"; var nstr=str.concat ("and Nick"); Console.log (str); // "Hello Tino"console.log (NSTR); // "Hello Tino and Nick"
Create a new string based on a substring:
Slice () accepts one to two arguments, the first argument is the start of the specified string, the second argument is where the string ends (the returned string does not include the location), and if there is no second argument, the end of the string is the ending position. If no arguments are passed, the original string is returned. The slice () method does not change the original string
var str= "Hello Tino"; Str.slice (5,9) // "Tino"Str.slice (5) // "Tino"Str.slice () //"Hello Tino"
The substr () method, like the slice () method, differs in that when the parameter is negative, the slice () method adds the passed-in negative value to the string length, and substr () adds the first negative value and the second negative argument to 0;
var str= "Hello Tino"; Console.log (Str.slice (-4)); // "Tino"Console.log (Str.substr ( -4)); // "Tino"Console.log (Str.slice (1,-4)); // "ell"Console.log (Str.substr (1,-4)); // ""
The substring () method also accepts two parameters, different from the first two, and substring () the second parameter is the number of characters represented.
JS String Manipulation method