search string in a text file
I want to search for a name of a co ordinate in a text file and then use the x and y values.
I did the programming in Java ready to program and there it works fine, but when I use the same method in eclipse it gives me the last co ordinates name with no x and y
Here is the code:
Code :
coordsuk1 =(EditText) findViewById(R.id.etJoin1);
searchco1 =(Button) findViewById(R.id.bSearchCo1);
searchco1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
try{
File myfile=new File("/sdcard/"+filename.getText().toString()+".txt");
FileInputStream filein=new FileInputStream(myfile);
BufferedReader br=new BufferedReader(new InputStreamReader(filein));
String reel = br.readLine ();
int tel = reel.indexOf (" ");
naamsuk1 = reel.substring (0, tel);
while (!naamsuk1.equals (coordsuk1))
{
reel = br.readLine ();
tel = reel.indexOf (" ");
naamsuk1 = reel.substring (0, tel);
}
coordnaam1join = reel.substring (0, tel);
coordy1 = Double.parseDouble (reel.substring (10, 22));
coordx1 = Double.parseDouble (reel.substring (26, 36));
Toast.makeText(getBaseContext(),
"Co ord '"+filename.getText().toString()+"' found",
Toast.LENGTH_SHORT).show();
}
catch(Exception e){
Toast.makeText(getBaseContext(), e.getMessage(),Toast.LENGTH_SHORT).show();
}
joinIntv1.setText("coordsuk1: "+coordsuk1);
joinIntv2.setText("naamsuk1: "+naamsuk1);
joinIntv3.setText("coordy1: "+coordy1);
joinIntv4.setText("coordx1: "+coordx1);
}
});
o and I get a blank Toast
The text file looks like this:
AB -42537.4098 24263.8160
ST4 -42677.9017 24201.6750
WODRC -42428.8129 24151.9450
MGDM -42369.8561 24128.2079
Re: search string in a text file
Re: search string in a text file
Thanks for posting a link to the solution. I do ask that you read the following:
http://www.javaprogrammingforums.com...s-posting.html