Reputation: 3
I have this android app that receives data from an excel file. Im using a libray to get the text from excel to a textView.I always have 3 columns in the excel I am receiving. For that reason I want to divide the string I receive into 3 positions in order to save in sqlite the information that excel gives and put them in the respective rows of the sqlite database.I want to know how to do a proper string split and store the information. This is the output of the app now that receives from the excel Thanks for your help in advanced.
try {
AssetManager am=getAssets();
InputStream is=am.open("Book1.xls");
Workbook wb =Workbook.getWorkbook(is);
Sheet s=wb.getSheet(0);
int row =s.getRows();
int col=s.getColumns();
String xx="";
for(int i=0;i<row;i++)
{
for (int c=0;c<col;c++)
{
Cell z=s.getCell(c,i);
xx=xx+z.getContents()+"\n";
//here I want to divide this string in three positions
}
xx=xx+"\n";
}
textView.setText(xx);
}
catch (Exception e)
{
}
Upvotes: 0
Views: 7107
Reputation: 300
Somthing like this :
Example :
String test ="aaa;bbb;ccc";
String fisrt ;
String second ;
String thrid ;
if(StringUtils.isNotEmpty(test)){ // test if str not null
String[] result = test .spit(";"); // you indicate your separator it can be espace or , or - ......
fisrt =result[0] // aaa
second =result[1] //bbb
thrid = result[2] // ccc
}
Upvotes: 0
Reputation: 1339
Do you want something like this?
String[] result = myString.split(" ");
String a = result[0];
String b = result[1];
String c = result[2];
Upvotes: 2