The following describes how to use string in javascript:
String class attribute and Method
Anchor () creates an <A> tag instance and sets its name attribute to the string passed to this method.
Big () converts a string to an instance of the <big> tag.
Blink () converts a string to an instance of the <blink> tag.
Bold () converts a string to an instance of the <bold> tag
Charat () returns the character passed to the index of this method
The Concat () connection returns a new string for the two passed strings.
Fixed () converts a character to an instance of the <tt> fixed pitch Font Tag
Fontcolor () sets the color attribute of a <font> tag instance.
Fontsize () sets the size attribute of a <font> tag instance.
Fromcharcode () returns the ISO-Latin-1 numeric character passed to this side
Indexof () returns the index of the string passed to this method for the first time in the instance of a sting object
Italics () converts a string to an instance of the <I> tag
Lastindexof () returns the index at the last occurrence of the string passed to this method in the instance of a sting object
Link () converts a string to an instance of the <A> tag and uses the herf attribute set by the URL passed to this method.
Match () returns an array that contains matches found by rule expressions passed to this method.
Replace () performs a search and replace with the rule expression passed to this method and the replacement string.
Search () returns the matched index location in the string passed to this method. If no distance is found,-1 is returned.
Slice () returns the string between the start and end indexes that are passed to this method. If a negative value is passed, the index uses the tail of the passed string as a reference.
Small () replaces a string with an instance of the <small> tag.
Split () returns the string that is segmented into segments. This split is defined by the string passed to this method and instance restrictions.
Strike () converts a string to an instance of the <strike> tag.
Sub () converts a string to an instance of the <sub> tag
Substr () returns a string that contains a certain number of characters to be returned starting from the indexed position. If a negative value is passed, the index uses the tail of the passed string as a reference.
Substring () returns the character between the passed start and end indexes.
Sup () converts a string to an instance of the <sup> tag.
Tolowercase () converts all characters in the string to lowercase
Tosource () returns the passed character as a string representation of the string object.
Tostring () returns the passed characters as the string type.
Touppercase () converts all characters in the string to uppercase
Length () returns the length of the string eg: var length = Str. length;
Prototype () provides a program with the ability to add attributes to a string object instance.
String class extension:
String. Prototype. tochararray = function (){
Return this. Split ("");
}
// Reverse Order
String. Prototype. Reverse = function (){
Return this. Split (""). Reverse (). Join ("");
}
// Whether the specified character is included
String. Prototype. iscontains = function (STR ){
Return (this. indexof (STR)>-1 );
}
// Judge whether it is null
String. Prototype. isempty = function (){
Return this = "";
}
// Determine whether it is a number
String. Prototype. isnumeric = function (){
VaR tmpfloat = parsefloat (this );
If (isnan (tmpfloat) return false;
VaR tmplen = This. length-tmpFloat.toString (). length;
Return tmpfloat + "0". getsame (tmplen) = This;
}
// Judge whether it is an integer
String. Prototype. isint = function (){
If (this = "Nan") return false;
Return this = parseint (this). tostring ();
}
// Merge multiple blanks into one blank
String. Prototype. resetblank = function (){
Return this. Replace (/S +/g ,"");
}
// Remove the left blank
String. Prototype. ltrim = function (){
Return this. Replace (/^ s +/g ,"");
}
// Remove the right Blank
String. Prototype. rtrim = function (){
Return this. Replace (/S + $/g ,"");
}
// Remove the blank spaces on both sides
String. Prototype. Trim = function (){
Return this. Replace (/(^ s +) | (S + $)/g ,"");
}
// Retain numbers
String. Prototype. getnum = function (){
Return this. Replace (/[^ d]/g ,"");
}
// Retain letters
String. Prototype. geten = function (){
Return this. Replace (/[^ A-Za-Z]/g ,"");
}
// Retain Chinese Characters
String. Prototype. getcn = function (){
Return this. Replace (/[^ u4e00-u9fa5uf900-ufa2d]/g ,"");
}
// Get the byte length
String. Prototype. bytelength = function ()
{
Return this. Replace (/[^/x00-/xFF]/g, "AA"). length;
}
// Extract a string of the specified length from the left
String. Prototype. Left = function (n ){
Return this. Slice (0, N );
}
// Extract a string of the specified length from the right
String. Prototype. Right = function (n ){
Return this. Slice (this. Length-N );
}
// Html Encoding
String. Prototype. htmlencode = function (){
VaR Re = this;
VaR Q1 = [/X26/g,/x3c/g,/x3e/g,/x20/g];
VaR q2 = ["&", "<", ">", ""];
For (VAR I = 0; I <q1.length; I ++)
Re = Re. Replace (Q1 [I], Q2 [I]);
Return re;
}
// Obtain Unicode
String. Prototype. Unicode = function (){
VaR tmparr = [];
For (VAR I = 0; I <this. length; I ++) tmparr. Push ("& #" + this. charcodeat (I) + ";");
Return tmparr. Join ("");
}
// Insert a string at the specified position
String. Prototype. Insert = function (index, STR ){
Return this. substring (0, index) + STR + this. substr (INDEX );
}
// Copy the string
String. Prototype. Copy = function (){
If (IE) window. clipboardData. setdata ("text", this. tostring ());
}
// Append the formatted string
String. Prototype. appendformat = function (STR ){
VaR Arg = arguments;
STR = Str. Replace (// {(/d +)/}/g, function (a, B, c)
{
If (ARG [parseint (B) + 1]) return Arg [parseint (B) + 1];
Else return;
});
Return this + STR;
}
Reprinted Source: http://blog.csdn.net/gabriel80/archive/2008/11/15/3304751.aspx