I have a program that retrieves value in an sqlite table using ArrayList. I am retrieving string data from it and count the length of string. The string will then be concatenated to another data if the total string count is less than or equal to 160. if total string count is greater than 160, it will not add the string.
The concept is like this:
- retrieve string
- variable a(which will hold the strings) will have the string retrieved concatenated to it.
- checks if a's length is less than or equal to 160. if less than go back to step (1), if not stop concatenating.
However, my program just add all strings without even counting if the length is over 160. This is my code:
List<Pending> pending = db.getAllPending();
String a="";
do{
for (Pending pn : pending) {
a += pn.getPm_str();
}
}while(a.length()<=160);
Log.d("s", a);
Logcat: RBSN/C1/12/3/4/8,CVTE/C1/2/3/4/1,RBSN/C1/4/2131/331/12,RBSN/C1/45/67/12/44,RBSN/C1/44/231/123/23213,RBSN/C1/444/55522/222/11,RBSN/C1/123/123/213123/1231232,RBSN/C1/2/3/1/1,
(string length is 172.)
Expected output should be RBSN/C1/12/3/4/8,CVTE/C1/2/3/4/1,RBSN/C1/4/2131/331/12,RBSN/C1/45/67/12/44,RBSN/C1/44/231/123/23213,RBSN/C1/444/55522/222/11,RBSN/C1/123/123/213123/1231232,RBSN/C1/2/3/1/1,
(string length is 156.)
Need your help guys.
Aucun commentaire:
Enregistrer un commentaire