Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6782481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:44:50+00:00 2026-05-26T16:44:50+00:00

I have a comma separated CSV file contains NASDAQ symbols . I use Scanner

  • 0

I have a comma separated CSV file contains NASDAQ symbols . I use Scanner to read a file

  s = new Scanner(new File("C:\\nasdaq_companylist.csv")).useDelimiter("\\s*,\\s*");    

I’m getting exception on second field .The problem is that this field , like some others fields in file contain commas too, for example “1-800 FLOWERS.COM, Inc.”:

FLWS,"1-800 FLOWERS.COM, Inc.",2.8,76022800,n/a,1999,Consumer Services,Other Specialty Stores,http://www.nasdaq.com/symbol/flws    

How to avoid this problem ?
My code is :

List<Stock> theList = new ArrayList<Stock>();
    StringBuilder sb = new StringBuilder();

    //get the title
    String title = s.nextLine();
    System.out.println("title: "+title);

    while (s.hasNext()) 
    {

        String symbol = s.next();
        String name = s.next();
        double lastSale = s.nextDouble();           
        long marketCap = s.nextLong();
        String adr =s.next();
        String ipoYear=s.next();
        String sector=s.next();
        String industry = s.next();
        String summaryQuote = s.next();
        theList.add(newStock(symbol,lastSale));} 

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:44:51+00:00Added an answer on May 26, 2026 at 4:44 pm

    Unless this is homework you should not parse CSV yourself. Use one of existing libraries. For example this one: http://commons.apache.org/sandbox/csv/

    Or google “java csv parser” and choose another.

    But if you wish to implement the logic yourself you should use negative lookahead feature of regular expressions (see http://download.oracle.com/javase/1,5.0/docs/api/java/util/regex/Pattern.html)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have idsfile.csv which is a comma separated file of ids (with no new
I have a CSV (comma separated values) file that contains student information. The column
I have a csv file that has 2 columns separated by a comma -
I have a comma separated CSV file looks like: customer1,customer2,,customer4, ,customer2,,customer4, custome1,,customer3,, I want
I have a comma separated file named foo.csv containing the following data: scale, serial,
I need to read a CSV file which has fields that have a comma,
I have a custom java program which produces a Comma Separated Values (CSV) file.
I have a bunch of pretty large CSV (comma separated values) files and I
If I have a comma separated file like the following: foo,bar,n ,a,bc,d one,two,three ,a,bc,d
I have a DB table that contains a comma separated list of ID's (ints)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.