Site hosted by Angelfire.com: Build your free website today!
 
MyersDaily Directories
Message Board | Lycos | JavaScripts.com
Your Pages | What's Up | Contents | Bottom of Page
[Home][Archive]

Do you hate the hassle of escaping quotes, newlines, etc. in strings?
Just let this script do it for you!!! You can choose Unicode or standard escapes as well as the option of replacing HTML characters with their corresponding entities (e.g. < to &lt;).


Copy-and-Paste String Functions



<script language="javascript1.1">

<!--

// Script by Joseph K. Myers <e_mayilme@hotmail.com>.


// This script produces a Unicode string with the turnIntoUnicodeString() function.
// This script produces a Unicode string with the turnIntoSafeString() function.
// HTML is escaped into entities with the escapeHTML() function.

o=unescape;
p=escape;


function sg(a,a2,a3) {
var r='';
while (a.indexOf(a2)!=-1) {
var v1=a.indexOf(a2);
r+=a.substring(0,v1)+a3;
a=a.substring(v1+a2.length);
} return r+a;
}


function escapeHTML(a) {
a=sg(a,'&','&amp;');
a=sg(a,'<','&lt;');
a=sg(a,'>','&gt;');
a=sg(a,'"','&quot;');
return a;
}

function turnIntoSafeString(a) {

a = sg(a,'\\','\\\\'); // Backslash backslashes
a = sg(a,'\n','\\n');  // Backslash newlines (Unix, Windows, DOS).
a = sg(a,'\r','\\r');  // Backslash newlines (Macintosh).
a = sg(a,'\t','\\t');  // Backslash tabs.
a = sg(a,'"','\\"');   // Backslash double quotes.
return '"' + a + '"';  // Return quoted string.

}

function turnIntoUnicodeString(a) {

return 'unescape("' + p(a) + '")';  // Return packed Unicode value.

}

//-->

</script>

Unicode String (Hexidecimal Escapes):
JavaScript String (Simple Escapes):
Escape HTML first:
   

This function is provided by Joseph K. Myers.

 
Enter keywords...  
Amazon.com logo Featured! | Send to a friend!
Home | Top | Feedback | Site Index | Best Photo
“MyersDaily” created by Joseph K. Myers 1999-2000. Free hosting by Angelfire!!
Note: This site's URL is: https://www.angelfire.com/yt/jmyers   Site Updated On: October 6, 2000
Terms-of-Service