var str="123abc456";
var i=3;
Copy the code

1 take the first I character of the string :(do not operate on the original character)

 str=str.substring(0,i);
Copy the code

2 take I characters from the right :(do not operate on the original character)

 str=str.substring(str.Length-i); 
Copy the code

3 remove I characters from the right :(do not operate on the original character)

 str=str.substring(0,str.Length-i);
Copy the code

4 if there is “ABC” in the string, replace with “ABC” :(operating on the original character)

str=str.replace("abc"."ABC");
Copy the code

5 if you want to start from the subscript of a character :(do not operate the original character)

str=str.substr(str.indexOf('a'), 3); // Truncate 3 elements from 'a' subscript (including 'a') without operating on the original characterCopy the code