LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 11-16-2006, 03:56 PM   #1
thefalling
LQ Newbie
 
Registered: Sep 2006
Posts: 14

Rep: Reputation: 0
Java question


Im trying to use the useDelimiter() function to break up data where there are commas, but when i output the data it works, but it outputs the comma. :S

myFile is my scanner object.


myFile.useDelimiter("\\s*,\\s*");

Is there another way to write this statement without the comma being saved?
 
Old 11-17-2006, 10:24 PM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 1,421

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
Scanner doesn't do that for me. Maybe you are outputing commas when you print? For instance Lists print commas between their elements.

Code:
import java.util.Scanner;
public class Delim {
    public static void main(String[] args) {
        Scanner scan = new Scanner("foo, bar, blah , as , ,,saf afa,");
        scan.useDelimiter("\\s*,\\s*");
        while(scan.hasNext())
            System.out.println(scan.next());
    }
}
That code gives me output:
Code:
~/src/java% java Delim                                                         
foo
bar
blah
as


saf afa
No commas here...
 
Old 11-22-2006, 02:01 PM   #3
djgerbavore
Member
 
Registered: Jun 2004
Location: PA
Distribution: Fedora Core 8_x86 (latest git kernel)
Posts: 434

Rep: Reputation: 30
you can also use the StringTokenizer Class. It works the similar way.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java question Jongi Suse/Novell 2 09-19-2005 01:07 PM
Java Question k1ll3r_x Programming 2 08-20-2005 08:10 PM
Java question biojayc Linux - Newbie 8 03-22-2005 03:42 PM
Java Question k1ll3r_x Programming 3 11-13-2004 04:27 AM
Question about Java Mega Man X Programming 3 12-27-2003 11:02 AM


All times are GMT -5. The time now is 04:43 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration