Java - take name from string -
i'm developing java application make statistic stuff.
this application take data .txt file supplied user. first line of file contains name of sets of data follows this:
velx,vely,velz
//various data
i need analyze first line , retrieve 3 name of variables, correctly first 2 i'm not able last one.
there code names:
public arraylist<string> gettitle(){ // arraylist not here in class intestation // copied here simplify code's understanding arraylist<string> title = new arraylist<string>(); try { inputstreamreader isr = new inputstreamreader(in); bufferedreader br = new bufferedreader(isr); stringbuilder sb = new stringbuilder(); int titlen = 0; string line = br.readline(); //read first line of file string temp; system.out.println(managetable.class.getname() + " line: " + line); int c = line.length(); for(int = 0; <c; i++){ if((line.charat(i) == ',') || **another condition** ){ temp = sb.tostring(); system.out.println(managetable.class.getname() +" temp is: " + temp); title.add(temp); system.out.println(managetable.class.getname() + " title added"); sb.delete(0, sb.length()); }else{ sb.append(line.charat(i)); } } } catch (ioexception ex) { logger.getlogger(managetable.class.getname()).log(level.severe, null, ex); } return title; }
i need add second condition if statement in order find out when line ended , save last name, if not followed ',' tried using:
if((line.charat(i) == ',') || (i==c))
but name get, miss character. how can check end of line , full name?
if line contains 3 names separated comma, can do
string[] names = line.split(",");
Comments
Post a Comment