Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: search string in a text file

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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:

          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


  2. #2
    Junior Member
    Join Date
    Feb 2012
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: search string in a text file


  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,264
    Thanks
    176
    Thanked 821 Times in 764 Posts
    Blog Entries
    5

    Default Re: search string in a text file

    Thanks for posting a link to the solution. I do ask that you read the following:
    The problems with cross-posting

Similar Threads

  1. changing particular string in text file
    By cute in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: November 6th, 2011, 10:03 AM
  2. Reading in entire contents of text file to one string
    By fortune2k in forum File I/O & Other I/O Streams
    Replies: 9
    Last Post: December 12th, 2010, 06:03 PM
  3. Text File into String Array
    By mathanv in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 12th, 2010, 04:30 AM
  4. reading string in from text file
    By basketball8533 in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: December 3rd, 2010, 04:31 PM
  5. Reading lines of a text file into a string array
    By fortune2k in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: November 11th, 2010, 10:56 AM