SoFunction
Updated on 2025-03-09

Collection of extension methods for javascript String

//Get the character array
=function()
{
         return ("");
}
//Get N identical strings
=function(num)
{
    var tmpArr=[];
    for(var i=0;i<num;i++)    (this);
    return ("");
}
//Reverse order
=function()
{
     return ("").reverse().join("");
}
//Test whether it is a number
=function()
{
    var tmpFloat=parseFloat(this);
    if(isNaN(tmpFloat))    return false;
    var tmpLen=().length;
    return tmpFloat+"0".Repeat(tmpLen)==this;
}
//Test whether it is an integer
=function()
{
    if(this=="NaN")    return false;
    return this==parseInt(this).toString();
}
// Merge multiple blanks into one blank
 = function()
{
    return (/s+/g," ");
}
// Remove the left blank
 = function()
{
    return (/^s+/g,""); 

// Remove the blank on the right
 = function()
{
    return (/s+$/g,""); 
}
// Remove the blanks on both sides
 = function()
{
    return (/(^s+)|(s+$)/g,""); 
}
// Keep the numbers
 = function()
{
    return (/[^d]/g,"");
}
// Reserve letters
 = function()
{
    return (/[^A-Za-z]/g,""); 
}
// Reserve Chinese
 = function()
{
    return (/[^u4e00-u9fa5uf900-ufa2d]/g,"");
}
// Get the byte length
 = function()
{
    return (/[^x00-xff]/g,"--").length;
}
// Seave the string of the specified length from the left
 = function(n)
{
    return (0,n);
}
// Seave the string of the specified length from the right
 = function(n)
{
    return (-n);
}
// HTML encoding
 = function()
{
    var re = this;
    var q1 = [/x26/g,/x3C/g,/x3E/g,/x20/g];
    var q2 = ["&","<",">"," "];
    for(var i=0;i<;i++)
    re = (q1[i],q2[i]);
    return re;
}
// Unicode conversion
 = function()
{
    var strText = "";
    for (var i=0; i<; i++) strText += "&#" + (i) + ";";
    return strText;