fbolavidez Posted September 24, 2007 Share Posted September 24, 2007 Helo! can anybody help me to resolve my problem about arraylist?any sample javascript code to put the content of the text file into arraylist...here is the sample output of text file:Strip_ID : B64210189 0003Origin_Location : 31011111111111 1111111111111 1111111111111 11111111111111111111111111 1111111111111 1111111111111 11111111111111111111111111 1111111111111 1111111011111 11111111111111111111111111 1111111111111 1111111111111 11111111111111111111111111 1111111111111 1111111111111 11111111111111111111111001 1111111111111 1111111110111 1111111111111plz....help me! thanks in advance!! :-) Link to comment Share on other sites More sharing options...
justsomeguy Posted September 24, 2007 Share Posted September 24, 2007 What do you want the structure of the array to be? Just all of the contents in the first element? Link to comment Share on other sites More sharing options...
fbolavidez Posted September 25, 2007 Author Share Posted September 25, 2007 What do you want the structure of the array to be? Just all of the contents in the first element?Thanks! Good day!i just want to put the content of the text file above starting in line no. 4 in an array then test if there are zero in the file...!thanks for your reply..:-) Link to comment Share on other sites More sharing options...
Shonumi Posted September 25, 2007 Share Posted September 25, 2007 Just so that you're aware, JS doesn't provide options for file I/O as would a much more complex language like C++ or Java. You can retrieve data, though, from files, but you cannot write to them. You should look into some AJAX concepts if all you need to do is fetch data.For what you need, an array is pointless, because in essence, a string in just an array of single characters. So to simplify things, just take the string of the 4th line by assigning a variable to it. If you want to test if there are any zeros in it, I'd go with the match() method. You can find its details here.http://www.w3schools.com/jsref/jsref_match.aspThough before any of this can be done, determine how you are going to get this data. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 25, 2007 Share Posted September 25, 2007 I'm still confused by what you want the array to be. Do you want the entire string in one array element, or each line in an element, or each character in it's own element? What are you trying to do? If all you're trying to do is check if the string contains a zero there is a much easier way. Link to comment Share on other sites More sharing options...
fbolavidez Posted September 26, 2007 Author Share Posted September 26, 2007 I'm still confused by what you want the array to be. Do you want the entire string in one array element, or each line in an element, or each character in it's own element? What are you trying to do? If all you're trying to do is check if the string contains a zero there is a much easier way.hi! i want each character in an array, then it will check each character of the string if it contains zero. thanks Link to comment Share on other sites More sharing options...
justsomeguy Posted September 26, 2007 Share Posted September 26, 2007 OK, you can break the string up into an array of characters like this:chars = file_text.split("");You can check if a zero is in the string like this:zero_exists = (file_text.indexOf("0") != -1);The zero_exists variable will be true if a 0 is in file_text, or false otherwise. Link to comment Share on other sites More sharing options...
fbolavidez Posted September 28, 2007 Author Share Posted September 28, 2007 OK, you can break the string up into an array of characters like this:chars = file_text.split("");You can check if a zero is in the string like this:zero_exists = (file_text.indexOf("0") != -1);The zero_exists variable will be true if a 0 is in file_text, or false otherwise.ok, how about i will check the array each character, then if i found zero in that location it will do something?For example, i have the content of text file below:1110111if(zero_exists){ ....do something here.. and tell the exact location of zero in text file or if the output is in the table form, the zero is found in column 4 and it will change the bgcolor of that cell..? thanks...} Link to comment Share on other sites More sharing options...
jesh Posted September 28, 2007 Share Posted September 28, 2007 If you have an array, you can iterate through the elements using a for loop: chars = file_text.split("");for(var i = 0; i < chars.length; i++){ if(chars[i] == "0") { alert(i + " is a zero!"); }} Your text field has two delimeters: "" and "\n" (or "\n\r"). You may want to split the text into lines by splitting on the newline character and then, for each line, split up the line into characters on the empty string (""). Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.