admin管理员组文章数量:1355221
I am trying to parse a text file that contains a bunch of test questions/answers to code a multiple choice test taker.
The questions and answers are all on separate lines so I need to read each file line by line and somehow parse it by just using html/javascript/jquery.
How would I do this? THANKS!
The text file has the extension .dat but is actually a text file. Its just the format these e in and there are too many to change... /?17bggsa47u4ukmx
I am trying to parse a text file that contains a bunch of test questions/answers to code a multiple choice test taker.
The questions and answers are all on separate lines so I need to read each file line by line and somehow parse it by just using html/javascript/jquery.
How would I do this? THANKS!
The text file has the extension .dat but is actually a text file. Its just the format these e in and there are too many to change... http://www.mediafire./?17bggsa47u4ukmx
Share Improve this question edited Mar 28, 2012 at 23:52 asked Mar 28, 2012 at 23:44 user1299463user1299463 1- please post a sample of the text file. Why are you not using json or XML? – FlavorScape Commented Mar 28, 2012 at 23:48
2 Answers
Reset to default 6try this
function readQAfile(filename){
$.ajax(filename,
{
success: function(file){
var lines = file.split('\n');
var questions = [];
var length = lines.length;
for(var i = 0; i < length; i+=2){
questions.push({
question: lines[i],
answer: lines[i+1] || "no answer"
})
}
window.questions = questions;
}
}
);
}
to use this you'll need to be running the website on a server (a local server is fine).
To get started try using regexp.
The following expression will split your text on every $$[number] occasion. From there you can brute force slice and cut and chop your string further.
Example code:
var regex = /(\$\$\d+)/g;
var str = "adasda$$1adadad$$23adsads\nadad\nadad$$3";
console.log(str.split(regex));
["", "$$1", "adad sad", "$$23", "asdad", "$$3", ""]
本文标签: How do you readparse a text file line by line using htmljavascriptStack Overflow
版权声明:本文标题:How do you readparse a text file line by line using htmljavascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743998532a2573433.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论