Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Help > Re: parsing CSV...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 6 Topic 16059 of 16078
Post > Topic >>

Re: parsing CSV data with quotation marks

by thufir <hawat.thufir@[EMAIL PROTECTED] > May 8, 2008 at 12:51 AM

On Thu, 08 May 2008 00:11:51 +0000, Stefan Ram wrote:


>   If this is an exercise, the teacher should give you a grammar for the
>   language of the source file.
> 
>   The name »CSV« does not refer to a specific formal language or
>   grammer.
> 
>   One can not write a scanner or a parser for a language that is not
>   specified.
>

By grammar, this is where things are headed:

		firstName = "Brenda";
		lastName = "Lee";

but maybe I'm not using Scanner correctly because guests.get(0) is the 
whole line, whereas I expected useDelimiter() to break it into smaller 
pieces based on using a comma as the delimiter.  I'll re-read the Sun 
tutorial, http://java.sun.com/docs/books/tutorial/essential/io/
scanning.html, but that's what I thought they were doing.


thufir@[EMAIL PROTECTED]
 
thufir@[EMAIL PROTECTED]
 cat src/a00720398/labs/Lab4.java
/**
 * Lab4.java
 */

package a00720398.labs;

import java.util.*;
import java.io.*;
import java.util.ArrayList;
import a00720398.util.*;
import a00720398.data.*;


public class Lab4 {
        public static void main (String[] args) {
//              scan();
//      }

//      public static void scan(){
                Scanner s = null;
                ArrayList<String> guests = new ArrayList<String>();

                try {

                        //Scanner s = new Scanner(input).useDelimiter("\
\s*fish\\s*");
                        s = new Scanner(new BufferedReader(new FileReader
("guests.txt"))).useDelimiter("/,");
                        while (s.hasNext()) {
                                String guest = s.next();
                                guests.add(guest);
                        }
                } catch (IOException e) {
                        System.out.println(e.getMessage());
                        e.printStackTrace();
                } finally {
                        if (s != null) {
                                s.close();
                        }
                }

        System.out.println(guests.get(0));

        }
}

thufir@[EMAIL PROTECTED]
 




thanks,

Thufir




 6 Posts in Topic:
parsing CSV data with quotation marks
thufir <hawat.thufir@[  2008-05-08 00:00:07 
Re: parsing CSV data with quotation marks
ram@[EMAIL PROTECTED] (S  2008-05-08 00:11:51 
Re: parsing CSV data with quotation marks
thufir <hawat.thufir@[  2008-05-08 00:51:30 
Re: parsing CSV data with quotation marks
Roedy Green <see_websi  2008-05-08 19:26:47 
Re: parsing CSV data with quotation marks
thufir <hawat.thufir@[  2008-05-08 01:15:04 
Re: parsing CSV data with quotation marks
Roedy Green <see_websi  2008-05-08 19:13:02 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 2:15:41 CDT 2008.