Js字符串操作函數(shù)大全
String.prototype.LTrim = function()
{
return this.replace(/(^\s*)/g, "");
}
String.prototype.Rtrim = function()
{
return this.replace(/(\s*$)/g, "");
}
String.prototype.Trim = function()
{
return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.Left = function(len)
{
if(isNaN(len)||len==null)
{
len = this.length;
}
else
{
if(parseInt(len)<0||parseInt(len)>this.length)
{
len = this.length;
}
}
return this.substr(0,len);
}
String.prototype.Right = function(len)
{
if(isNaN(len)||len==null)
{
len = this.length;
}
else
{
if(parseInt(len)<0||parseInt(len)>this.length)
{
len = this.length;
}
}
return this.substring(this.length-len,this.length);
}
String.prototype.Mid = function(start,len)
{
return this.substr(start,len);
}
String.prototype.InStr = function(str)
{
if(str==null)
{
str = "";
}
return this.indexOf(str);
}
String.prototype.InStrRev = function(str)
{
if(str==null)
{
str = "";
}
return this.lastIndexOf(str);
}
String.prototype.LengthW = function()
{
return this.replace(/[^\x00-\xff]/g,"**").length;
}
String.prototype.isIP = function()
{
var reSpaceCheck = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;
if (reSpaceCheck.test(this))
{
this.match(reSpaceCheck);
if (RegExp.$1 <= 255 && RegExp.$1 >= 0
&& RegExp.$2 <= 255 && RegExp.$2 >= 0
&& RegExp.$3 <= 255 && RegExp.$3 >= 0
&& RegExp.$4 <= 255 && RegExp.$4 >= 0)
{
return true;
}
else
{
return false;
}
}
else
{