Parse Text
Chu Alan Jun 6, 2001
Quickly and easily convert text into a JavaScript string. Neat!
(There are two pages in this demo)
The JavaScript Source: Forms: Parse Text
Simply click inside the window below, use your cursor to highlight the script, and copy (type Control-c or Apple-c) the script into a new file in your text editor (such as Note Pad or Simple Text) and save (Control-s or Command-s). The script is yours!!!
<!-- TWO STEPS TO INSTALL PARSE TEXT (Page 1 of 2):
1. Copy the coding into the HEAD of your HTML document
2. Add the last code into the BODY of your HTML document -->
<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Chu Alan -->
<!-- Web Site: http://www.methylated-spirit.com -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://www.javascriptsource.com -->
<!-- Begin
var isNav4, isIE4;
if (parseInt(navigator.appVersion.charAt(0)) >= 4) {
isNav4 = (navigator.appName == "Netscape") ? true : false;
isIE4 = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
}
var resultWnd
function parsetext(form) {
resultWnd = open("parse-result.html", null, "toolbar=no,menubar=no,width=600,height=150,screenX=0,screenY=0");
}
// End -->
</script>
</HEAD>
<!-- STEP TWO: Copy this code into the BODY of your HTML document -->
<BODY>
<FORM action="" onSubmit="parsetext(this) ; return false">
<TEXTAREA name="texttoparse" rows="10" cols="50"></TEXTAREA><BR><BR>
<INPUT type="submit" value=" Parse text " style="font: 12pt Verdana">
</FORM>
<p><center>
<font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>
<!-- Script Size: 1.38 KB --> Did you use this script? Do you like this site? Please link to us!
The JavaScript Source: Forms: Parse Result Page
Simply click inside the window below, use your cursor to highlight the script, and copy (type Control-c or Apple-c) the script into a new file in your text editor (such as Note Pad or Simple Text) and save (Control-s or Command-s). The script is yours!!!
<!-- THREE STEPS TO INSTALL PARSE RESULT PAGE (Page 2 of 2):
1. Copy the coding into the HEAD of your HTML document
2. Add the onLoad event handler into the BODY tag
3. Put the last coding into the BODY of your HTML document -->
<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Chu Alan -->
<!-- Web Site: http://www.methylated-spirit.com -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://www.javascriptsource.com -->
<!-- Begin
var bShowslashr = false;
var bEscapegtlt = true;
function replace(str, original, replacement) {
var result;
result = "";
while(str.indexOf(original) != -1) {
if (str.indexOf(original) > 0)
result = result + str.substring(0, str.indexOf(original)) + replacement;
else
result = result + replacement;
str = str.substring(str.indexOf(original) + original.length, str.length);
}
return result + str;
}
function parse() {
var strParse = window.opener.document.forms[0].elements["texttoparse"].value;
strParse = replace(strParse, "\\", "\\\\");
if (bShowslashr)
strParse = replace(strParse, "\r", "\\r");
else
strParse = replace(strParse, "\r", "");
strParse = replace(strParse, '"', '\\"');
strParse = replace(strParse, "'", "\\'");
strParse = replace(strParse, "\t", "\\t");
if (bEscapegtlt) {
strParse = replace(strParse, "<", "\\<");
strParse = replace(strParse, ">", "\\>");
}
while(strParse.indexOf("\n") != -1)
strParse = strParse.substring(0, strParse.indexOf("\n")) + "\\n" + strParse.substring(strParse.indexOf("\n") + 1, strParse.length);
document.forms[0][0].value = strParse;
}
function showslashr() {
bShowslashr = !bShowslashr;
parse();
}
function escapegtlt() {
bEscapegtlt = !bEscapegtlt;
parse();
}
// End -->
</script>
</HEAD>
<!-- STEP TWO: Insert the onLoad event handler into your BODY tag -->
<BODY onLoad="parse()">
<!-- STEP THREE: Copy this code into the BODY of your HTML document -->
<FORM action="">
<INPUT type="text" size="75"><BR>
<a href="javascript:document.forms[0][0].focus() ; document.forms[0][0].select()">[select all]</a>
<br><br>
<b>-- options --</b><br>
<input type="checkbox" onclick="showslashr()"> Show \r<br>
<input type="checkbox" onclick="escapegtlt()" checked> Convert > to \> and < to \<
</FORM>
<p><center>
<font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>
<!-- Script Size: 2.55 KB --> Did you use this script? Do you like this site? Please link to us!
Leave a Response
(1 comment)Thanks,,,