Hello friends,
I am attempting to open a .txt file and read in its contents. With every line from the file, I would like to append a comma and single-quote to the beggining, and a single quote at the end of the string/line.
example:
Original file:
Apple
Orange
Plum
Expected result:
,'Apple'
,'Orange'
,'Plum'
Please take a look at my code and let me know what I am doing wrong. Thanks a milion.
<html xmlns:javaScriptDownload>
<head>
<title>Appending quotations and commas to Elite folder Id</title>
<script type="text/javascript">
// set the hidden field's value to the contents of the text file
// we store the text here after the download.
function setDlProc(obj) {
document.all.download.value=obj;
}
// parse over the contents, since we want to have each fruit on it's own line
// we replace all newline characters(\n) with an HTML newline(<BR>)
function writeToDoc(){
var re = new RegExp ("\n","g");
str = document.getElementById("download").value.replace(re,"'<br>,'");
// str = str.replace(re,"<br>");
document.getElementById('textFileCOntentsOnPage').innerHTML = str;
}
function runTest(){
// invoke the behavior on the namespace specified download page object
document.getElementById('fileDlBehavior').startDownload('test.txt',setDlProc);
// set the contents of the display area to show that we're getting the file
document.getElementById('textFileCOntentsOnPage').innerHTML = "Downloading
the text file...";
// write the contents of the text file to the page display area
setTimeout("writeToDoc()", 1500);
}
</script>
</head>
<body>
<!- the the button you click to invoke the test -->
<input type='button' value='Press To Run Program' onclick="runTest()"><hr>
<!- the namespace specified download page object -->
<javaScriptDownload:download id="fileDlBehavior"
style="behavior:url(#default#download);" />
<!- the hidden field that stores the text file contents after download -->
<input type='hidden' id="download" name='download' style='visibility:hidden'>
<!- The display area for the test results -->
<span id='textFileCOntentsOnPage' name='textFileCOntentsOnPage'></span>
</body>
</html>
I am attempting to open a .txt file and read in its contents. With every line from the file, I would like to append a comma and single-quote to the beggining, and a single quote at the end of the string/line.
example:
Original file:
Apple
Orange
Plum
Expected result:
,'Apple'
,'Orange'
,'Plum'
Please take a look at my code and let me know what I am doing wrong. Thanks a milion.
<html xmlns:javaScriptDownload>
<head>
<title>Appending quotations and commas to Elite folder Id</title>
<script type="text/javascript">
// set the hidden field's value to the contents of the text file
// we store the text here after the download.
function setDlProc(obj) {
document.all.download.value=obj;
}
// parse over the contents, since we want to have each fruit on it's own line
// we replace all newline characters(\n) with an HTML newline(<BR>)
function writeToDoc(){
var re = new RegExp ("\n","g");
str = document.getElementById("download").value.replace(re,"'<br>,'");
// str = str.replace(re,"<br>");
document.getElementById('textFileCOntentsOnPage').innerHTML = str;
}
function runTest(){
// invoke the behavior on the namespace specified download page object
document.getElementById('fileDlBehavior').startDownload('test.txt',setDlProc);
// set the contents of the display area to show that we're getting the file
document.getElementById('textFileCOntentsOnPage').innerHTML = "Downloading
the text file...";
// write the contents of the text file to the page display area
setTimeout("writeToDoc()", 1500);
}
</script>
</head>
<body>
<!- the the button you click to invoke the test -->
<input type='button' value='Press To Run Program' onclick="runTest()"><hr>
<!- the namespace specified download page object -->
<javaScriptDownload:download id="fileDlBehavior"
style="behavior:url(#default#download);" />
<!- the hidden field that stores the text file contents after download -->
<input type='hidden' id="download" name='download' style='visibility:hidden'>
<!- The display area for the test results -->
<span id='textFileCOntentsOnPage' name='textFileCOntentsOnPage'></span>
</body>
</html>