Tuesday, September 13, 2022

Enocoding long string in Javascript

 unction Encode(values) {


    var newValue = values;


    if (newValue) {


        if (newValue.indexOf('%') > -1)

            newValue = newValue.replace(/%/g, '%25');


        if (newValue.indexOf('"') > -1)

            newValue = newValue.replace(/"/g, '%22');


        if (newValue.indexOf('\\') > -1)

            newValue = newValue.replace(/\\/g, '%5C');


        if (newValue.indexOf('{') > -1)

            newValue = newValue.replace(/{/g, '%7B');


        if (newValue.indexOf('}') > -1)

            newValue = newValue.replace(/}/g, '%7D');


        if (newValue.indexOf("'") > -1)

            newValue = newValue.replace(/'/g, "'");

    }

    return newValue;

}


 row.EmbedCode = decodeURIComponent(Encode(row.EmbedCode));