#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Having trouble with delimiters in scanner


    hi

    i wanted to use the scanner to read a text file containing some source code and output it one statement at a time but am having trouble since sometimes there might be more than one statement on a line.

    i wanted to use ; as a delimiter but i doesn't seem to work properly

    the sample text am using is just :

    cat;
    dog;
    fish;salmon;beef;
    pork;boom;

    i wanted to have each on a separate line ie

    cat;
    dog;
    fish;
    salmon;
    beef;
    pork;
    boom;


    Code:
        public static void main(String[] args) {
            
            try{
                
                Scanner input = new Scanner(new File("code.txt")).useDelimiter("/;/g");
                
               
        	
               
        	while(input.hasNext())
        	{
        		
        		 String line = input.next();
        	
                System.out.println(line);
     
        		
        	}            
                
            }
            catch(Exception ex){
                System.out.println(ex);
            }
            
        }
    but its just returning the file as written
    can anybody help ?
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    oups


    oh i just fixed it, thanks anyway guys

IMN logo majestic logo threadwatch logo seochat tools logo