We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi There, I have a text file, which has serialdata sent from a Arduino. The text file containing the data has a set of coordinates, (say x,y,z) which is stored in a continuous stream, but has CRLF breaks after a number of data pertaining to a timeframe. For example
1245
909 1105
1096 768
The data above is really x,y,z with following values (note : x takes two digits always, and first is left blank if x is less than 10)
(12,4,5)
(9,0,9), (11,0,5)
(10,9,6),(7,6,8)
I need to find the maximum and minimum of the x values in the file.
i've managed to read the data using following program
void setup()
{
noLoop();
size(100,100);
background(153);
int lf = 10; // Linefeed in ASCII
}
void draw(){
String filename=dataPath("test.txt");
String[] data = loadStrings(filename);
String[] lines = split(data,lf); //doesn't work
println(data);
}
can someone suggest how I can split the text into different strings by using splitdata (or some other method)- I cant seem to give LF to break the string.
Many Thanks, Genny
Answers
AFAIK, loadStrings() already splits a whole text into lines as array slots using CR &/or LF as end of line characters!
BtW, CR = RETURN = '\r'. And LF = ENTER = '\n'.
Thanks GoToLoop!.
Yes you were right. I thought it split-ted using space. Btw hit a problem parsing a line of text
I get an error saying Substring cannot be resolved (for calculating length of one line) Basically what im trying to do is to get the substring length (Say12 or 8) and divide by 4 which gives me the no. of coordinates in that line.
http://processing.org/reference/String_length_.html
Thank you GotoLoop!. I'll post my complete code to replace this post soon!
Here is the working program :)
@gennylk, I've made a more complex alternative version just for fun. (*)
Dunno whether it still works for your files though! :-SS