Thomas said:
Dr John Stockton wrote:
There is no reason that she is interested in it, either.
<snip>
Return of the original poster... Sorry I've been rather busy and haven't
been able to follow this very interesting thread more closely. (The OP is
male, by the way.) However, judging by the complexity of the discussion, it
seems that there was some reason for my original perplexity, though I
thought it a trivial notion.
First let me try to clarify what I'm doing. I know that JavaScript has no
access to the file system. The files are to be handled directly by the user
of the utility. In the Windows environment, this is trivial with ^A, ^C, and
^V. I didn't mention that part because it's almost mindless now (for me).
The actual steps for the file part are:
Open the converter JavaScript form, then open the target file, ^A, ^C, click
in the form, ^V, click on the convert button of the form, ^A, ^C, click back
in the original file, ^A, ^V, and save the file. Done. (If anyone is curious
and the results of these steps are not obvious enough, I can explain.)
Now to clarify the JavaScript part. This example is from an existing utility
that converts raw HTML into JavaScript. The variable HtmlText is the body of
the file from an input field in the form. The critical function is:
function jsFromHtml(HtmlText) {
HtmlText = HtmlText.replace(/\"/g,"\\\"");
HtmlText = HtmlText.replace(/[\r\n]+/g,"\");\r\ndocument.writeln(\"");
return "document.writeln(\"" + HtmlText + "\");";
}
I know this is rather ugly code, and I'd also be interested in improvements,
or even a completely different approach. My JavaScript skills are obviously
rather limited, but this was adequate for my purposes at the time. Since
it's probably not IOttMCO, I'll explain what it does. In the first
executable line, the regular expression escapes all of the double quotes in
the original HTML. In the next line, all of the embedded line breaks are
replaced with the end and start of document.writeln statements, and then the
last line puts one more start and end around the entire thing. The result is
a block of JavaScript code which outputs the arbitrary HTML input. You stick
that into a JavaScript function to create that block of HTML under program
control wherever it is required. (I was especially unhappy with my treatment
of line breaks, and believe this is not a properly general method, though it
works.)
My goal now is to do something similar, but excluding the lines that do not
contain some string. I'm most interested in an elegant solution, though the
discussion so far seems to suggest that there may be no better approach than
parsing the input one line at a time...
An additional wrinkle is that I'd like to generalize a bit by treating the
decision string as a parameter returned in another field of the form.