string - im getting following exception when doing following code: java.lang.StringIndexOutOfBoundsException -
//for loop traversing rows (int = 1 ; < roorws.getcount() ; i++) { // loop traversing columns (int j = 1 ;j<tcols ; j++) { //if column 5 if(j==5) //printing values of cell 5 system.out.print(cells.get(i,j).getvalue().tostring().substring(0, 26).length()+ "\t"); string cell1=cells.get(i,j).getvalue().tostring().substring(0, 26); cell=cells.get("f2"); cell.putvalue(cell1); } system.out.println(""); }
apparently length of string not (at least) 26 characters. change:
system.out.print(cells.get(i,j).getvalue().tostring().substring(0, 26).length()+ "\t");
to:
system.out.print(cells.get(i,j).getvalue().tostring().length()+ "\t");
to print length of string.
you can use apache commons stringutils substring() method sub string in safe way (so takes @ n
characters):
string cell1= stringutils.substring(cells.get(i,j).getvalue().tostring(), 0, 26);
Comments
Post a Comment