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 > parsing CSV dat...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 6 Topic 16059 of 16070
Post > Topic >>

parsing CSV data with quotation marks

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

The text file really is CSV, but I also need to strip out the quotation 
marks.  I suppose I can use the comma as a delimiter and then strip out 
the quotation marks, but I feel like there's a better idiom.  Any 
pointers?  (yes, I'll replace "foos" with guests.)


thufir@[EMAIL PROTECTED]
 
thufir@[EMAIL PROTECTED]
 
thufir@[EMAIL PROTECTED]
 cat src/a00720398/util/guests.txt
"Lee", "Brenda", "(604) 636-1000", "b.lee@[EMAIL PROTECTED]
"
thufir@[EMAIL PROTECTED]
 
thufir@[EMAIL PROTECTED]
 cat src/a00720398/labs/Lab4.java
/**
 * Lab4.java
 */

package a00720398.labs;

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


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

        public static void scan(){
                Scanner s = null;
                List<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);

        }
}

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 Mon May 12 2:15:36 CDT 2008.