String.prototype.trim =
function
(tag) {
if
(!tag) {
tag =
'\\s'
;
}
else
{
if
(tag ==
'\\'
) {
tag =
'\\\\'
;
}
else
if
(tag ==
','
|| tag ==
'|'
|| tag ==
';'
) {
tag =
'\\'
+ tag;
}
else
{
tag =
'\\s'
;
}
}
eval(
'var reg=/(^'
+ tag +
'+)|('
+ tag +
'+$)/g;'
);
return
this
.replace(reg,
''
);
};
String.prototype.interceptString =
function
(len) {
if
(
this
.length > len) {
return
this
.substring(0, len) +
"..."
;
}
else
{
return
this
;
}
}
String.prototype.toArray =
function
(tag) {
if
(
this
.indexOf(tag) != -1) {
return
this
.split(tag);
}
else
{
if
(
this
!=
''
) {
return
[
this
.toString()];
}
else
{
return
[];
}
}
}
String.prototype.toNumber=
function
() {
return
this
.replace(/\D/g,
""
);
}
String.prototype.toCN=
function
() {
var
regEx = /[^\u4e00-\u9fa5\uf900-\ufa2d]/g;
return
this
.replace(regEx,
''
);
}
String.prototype.toInt=
function
() {
var
temp =
this
.replace(/\D/g,
""
);
return
isNaN(parseInt(temp)) ?
this
.toString() : parseInt(temp);
}
String.prototype.startsWith=
function
(tag){
return
this
.substring(0, tag.length) == tag;
}
String.prototype.endWith=
function
(tag){
return
this
.substring(
this
.length - tag.length) == tag;
}
var
StringBuffer =
function
() {
this
._strs =
new
Array;
};
StringBuffer.prototype.append =
function
(str) {
this
._strs.push(str);
};
StringBuffer.prototype.toString =
function
() {
return
this
._strs.join(
""
);
};
String.prototype.replaceAll =
function
(s1,s2){
return
this
.replace(
new
RegExp(s1,
"gm"
),s2);
}