java - retrieve phone number from text file using indexOf -


i have text file has details date,time,phone number, etc. trying retrieve these details using java indexof concept. however, digits in phone number change depending on type of call.

how can improve code able retrieve every phone number file. here's i've been trying :

bufferedreader reader = new bufferedreader(new filereader(filepath));             string getindex=""; while ((line = reader.readline()) != null) {       line = line.replaceall("[\\s]+", " ");   //remove large spaces file.      /*          dialledno chosen of combo box.          calculating start , end index in order print dialled no.         */      int startindex = getindex.indexof(dialledno);      int endindex = getindex.indexof(" ", startindex);      strdialedno= (startindex + "," + endindex); 

and code retrieve number mentioned below :

string[] arrdialedno = strdialedno.split(",");  int dialednostart = integer.parseint(arrdialedno[0]); int dialednoend = integer.parseint(arrdialedno[1]);  dialedno = line.substring(dialednostart, dialednoend); 

this how text file looks like:

0356  524           000   8861205063        12/03 18:59    00:08     01:20 0357  524           000   9902926868        12/03 20:01      0373  511           000   09886863637       13/03 11:46    01:01     02:40  s 0376  504           000   9845014967        13/03 11:46    00:11     01:20 0382  508           000   04443923200       13/03 12:04    03:11     04:80  s 0411  516           000   8884103111        13/03 16:25    01:03     01:20 

this should work,

string[] b = line.split(" ");     string phonenumber = null;     (string x : b) {         boolean z = false;         if (x.length() == 10) {              char[] c = x.tochararray();             (char g : c) {                 if (character.isdigit(g)) {                     z = true;                 } else {                     z = false;                     break;                 }             }          } else {             z = false;         }         if (z) {             phonenumber = x;         } } 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -