开发者

android sqlite indexof()

开发者 https://www.devze.com 2023-02-19 06:33 出处:网络
hi to all im reading this format from a file BOOKNO= [1] From= [ 2011-02-28 07:00:52] To= [2011-03-17 07:01:02]

hi to all im reading this format from a file

BOOKNO= [1] 
From= [ 2011-02-28 07:00:52] 
To= [2011-03-17 07:01:02]
Link= [http://www.example.com]
SINCE= [5] days.
BOOKNO= [2] 
From= [ 2011-03-01 17:55:15] 
To= [2011-03-30 17:55:21]
Link= [http://www.something.com]
SINCE= [3] days.

and i need to insert what is between the brackets only into an sqlite database

and its not working .....!! any suggestions on how to fix it or any other good ideas on how to read it and insert it to my database columns

NOTE: addressString has the information that needs to be inserted into the tabel and i have 5 columns BOOK,FROM,TO,LINK, and SINCE and when i read the file i get the information for all the books (more than 1 book)... thats why im using indexof() and for loop 'J' so i can insert 5 columns and loop to insert the next 5....

this is the code:

 db.open();        
        long idx;

        String lines[] = {addressString};
        String fields[] = new String[lines.length];
        for (int i = 0; i < lines.length; i++) {

            for (int j=0; j<5; j++){
            int be = lines[i].indexOf('[');
            int e = lines[i].indexOf(']');
            fields[i] = lines[i].substring(be+1, e);
            idx = db.insertTitle(fields[0],fields[1],fields[2],fields[3],fields[4]);
        }
            }

hi to all again i've been playing around with my code and when i try to show the output on the screen with this code i get only number 1 on the screen it does not read all the text that is in address string

    if (addressString != "didn't read titels"){
        String lines[] = {addressString};
        String fields[] = new String[lines.length];     
for (in开发者_Python百科t i = 0; i < lines.length; i++) {
                int be = lines[i].indexOf('[');
                int e = lines[i].indexOf(']');
                fields[i] = lines[i].substring(be+1, e);
                myLoutputText.setText(fields[i]);
    }


db.insertTitle(...) should be outside the for loop (controlled by j).

0

精彩评论

暂无评论...
验证码 换一张
取 消