Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By jim829

Thread: Removing quotes:

  1. #1
    jocdrew21 is offline Member
    Join Date
    Jan 2014
    Posts
    62
    Rep Power
    0

    Default Removing quotes:

    I found this program idea online. It has 5000 names written as "SOMENAME","SOMEOTHERNAME","ETC" and I have to spilt them up and do a few other things. Well I spilt them up but I cannot get rid of the quotes. I like to do it before I pass it into the ArrayList so that I can tackle the next step of the program. Any ideas?

    Java Code:
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.util.ArrayList;
    
    public class SplitList
    {
    	ArrayList<String> myList = new ArrayList<String>();
    	String array[];
    	private String line = "";
    	int counter = 0;
    
    	void readFile() throws Exception
    	{
    		FileReader inFile = new FileReader("names.txt");
    		BufferedReader buffer = new BufferedReader(inFile);
    		
    		while((line = buffer.readLine()) != null)
    		{
    			array = line.split(",");
    			
    			for(int i=0; i<array.length;i++)
    			{
    			   myList.add(array[i]);
    			}
    				
    		}
    		
    		inFile.close();
    	}
    	
    	void printFile()
    	{
    		
    		for(int i=0; i<myList.size();i++)
    		{
    			System.out.println(myList.get(i));	
    		}
    		
    	}
    	
    	public static void main(String[] args) 
    	{
    		SplitList s = new SplitList();
    		
    		try{
    		s.readFile();
    		}catch(Exception ex)
    		{
    			System.out.println("Unable to open or find file");
    		}
    		s.printFile();
    		
    	}
    }

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,544
    Rep Power
    5

    Default Re: Removing quotes:

    There are a variety of approaches. I prefer regular expressions. But you could just split them based on their commas (,) and then simply use the String functions to search for the quotations marks and simply delete them. Check out java.util.regex and java.lang.String.

    Regards,
    Jim
    jocdrew21 likes this.
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. checking for quotes in a string
    By kilyx in forum New To Java
    Replies: 3
    Last Post: 12-15-2011, 12:06 AM
  2. Quotes around variables
    By jadroe in forum New To Java
    Replies: 3
    Last Post: 03-16-2011, 09:49 PM
  3. unbalanced quotes in -
    By fresh83 in forum New To Java
    Replies: 2
    Last Post: 12-19-2009, 01:10 AM
  4. Stock Quotes
    By BartDR in forum Advanced Java
    Replies: 0
    Last Post: 09-15-2009, 09:15 AM
  5. The Fav. Programming Quotes Thread
    By angryboy in forum Forum Lobby
    Replies: 3
    Last Post: 06-13-2009, 10:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •