摘自启点的main.js
2024-05-06 14:18:08
供稿:网友
String.prototype.trim = function()
{
return this.replace(/(^/s*)|(/s*$)/g, "");
}
String.prototype.len=function()
{
return this.replace(/[^/x00-/xff]/g,'aa').length;
}
function StringBuilder(value)
{
this.strings = new Array("");
this.append(value);
}
// Appends the given value to the end of this instance.
StringBuilder.prototype.append = function (value)
{
if (value)
{
this.strings.push(value);
}
}
// Clears the string buffer
StringBuilder.prototype.clear = function ()
{
this.strings.length = 1;
}
// Converts this instance to a String.
StringBuilder.prototype.toString = function ()
{
return this.strings.join("");
}
//string format prototype
// sample: var test="my name is {0} {2} " ;
// alert(test.format('liang','zhonghua');
if (!String._FORMAT_SEPARATOR){
String._FORMAT_SEPARATOR = String.fromCharCode(0x1f);
String._FORMAT_ARGS_PATTERN = new RegExp('^[^' + String._FORMAT_SEPARATOR + ']*'
+ new Array(100).join('(?:.([^' + String._FORMAT_SEPARATOR + ']*))?'));
}
if (!String.format)
{
String.format = function (s){
return Array.prototype.join.call(arguments, String._FORMAT_SEPARATOR).
replace(String._FORMAT_ARGS_PATTERN, s);
}
}
if (!''.format)
{
String.prototype.format = function (){
return (String._FORMAT_SEPARATOR +
Array.prototype.join.call(arguments, String._FORMAT_SEPARATOR)).
replace(String._FORMAT_ARGS_PATTERN, this);