Jerminix

"Ramblings in Life Events On and Offline"

June 25th, 2009 | by | javascript, web

Jun
25

This is the reversal part of my previous post

Convert string to special characters you want using replace() function in javascript. Useful when converting characters to be saved in the database or passed as a parameter in a url.

function convertSC(oldstring)
{

oldstring = oldstring.replace(/_DQ_/g, “”");
oldstring = oldstring.replace(/_SQ_/g, “‘”);
oldstring = oldstring.replace(/_@_/g, “&”);
oldstring = oldstring.replace(/_AND_/g, “&”);
oldstring = oldstring.replace(/_LT_/g, “<");
oldstring = oldstring.replace(/_GT_/g, “>”);
oldstring = oldstring.replace(/_PC_/g, “%”);
oldstring = oldstring.replace(/_DQ_/g, “”");

return oldstring;
}

Example:
var convertme = convertSC(“Total is 100_PC_”);
alert(converme);

Output:
Total is 100%

Related Posts Plugin for WordPress, Blogger...

Related posts:

  1. Javascript : How to convert special characters to any string

Authored by

A Pinoy Cebu based blogger, Gamer, Web Developer, Event Wanderer and wanna be photographer blogging about everything and anything under the sun.

Leave a Comment

CommentLuv badge

Featuring Recent Posts WordPress Widget development by YD