Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Java in General
Pipe Seperated file using Scanner
Kedar Kulkarni
Greenhorn
Posts: 2
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hello I am trying to parse a pipe separated line using Scanner. It does not seem to work. It tokenizes every character. Can some one give me some clues?
import java.util.Scanner; public class test { public static void main(String[] args) { String line = "The|quick|brown|fox|jumps|over|the|lazy|dog"; Scanner lineScanner = new Scanner(line); lineScanner.useDelimiter("|"); System.out.println("Check Delimiter: "+lineScanner.delimiter()); while (lineScanner.hasNext()) { System.out.println("Tokens: "+lineScanner.next().trim()); } lineScanner.close(); } }
?
Henry Wong
author
Posts: 23951
142
I like...
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
The pipe symbol has special meaning in a regex -- so you need to escape it.
Henry
Books:
Java Threads, 3rd Edition
,
Jini in a Nutshell
, and
Java Gems (contributor)
Kedar Kulkarni
Greenhorn
Posts: 2
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
cool this works!! thanks
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
how do i input
Scanner
Study Material for Scanner and Fromatter
how to split a text file
Having problem with Scanner
More...