The examples in this article describe the common API functions for JavaScript string objects. Share to everyone for your reference, specific as follows:
1. Concat (str1,str2,)
Connection string
2. IndexOf (Str,start)
Returns the position of the first occurrence of STR in a string
var str = "Hello world";
Str.indexof ("Hello"); 0
str.indexof ("O", 5);//7
Str.indexof ("World");//-1
3. LastIndexOf (Str,start)
Returns the last occurrence of str in a string
var str = "Hello world";
Str.lastindexof ("Hello"); 0
str.lastindexof ("O", 3);//-1
str.lastindexof ("O", 5);//4
4. Replace (regexp/substr,replacement)
Substitute some characters in a string for another character, or replace one with a regular match
var str = "I is Allen.";
Str.replace ("is", "AM"); "I am Allen."
5. Slice (start,end)
Returns a fragment of a string
var str = "I am Jack.";
Str.slice (3,7); "M Ja"
str.slice (3);//"M Jack."
Str.slice (3,-3); "M Ja"
6. Split (Separator,limit)
Splits a string into substrings and then returns the result as an array of strings
var str = "Hello world";
Str.split (""); ["Hello", "World"]
str.split ("", 1); ["Hello"]
7. substr (Start,lenght)
Returns a string with a specified length starting at the specified position
var str = "How do I do?"
Str.substr (4,2); "
do
" str.substr (4); Str.substr (4,0); ""
str.substr (4,-1); ""
Str.substr (-3); "Do?"
8. SUBSTRING (start,end)
Returns a string at the specified position in a string object that contains the character at start, but does not contain a character at the end
var str = "How do I do?"
Str.substring (0,3); "How"
9. toLowerCase ()
Converts a string to lowercase
toUpperCase ()
Converts a string to uppercase
var str = "How do I do?"
Str.tolowercase (); "How did you do?"
Str.touppercase (); "How did you do?"
More readers interested in JavaScript-related content can view this site: "JavaScript in the JSON Operation tips Summary", "JavaScript switching effects and techniques summary", "JavaScript Search Algorithm Skills summary", " JavaScript animation effects and tips Summary, "JavaScript Error and debugging skills Summary", "JavaScript data structure and algorithm skills summary", "JavaScript traversal algorithm and Skills summary" and "JavaScript Mathematical operation Usage Summary"
I hope this article will help you with JavaScript programming.