• 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

Parsing

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey gurus,
Could anybody help me with the following:
1) A way to parse hard tab delimited feed
Eg. " a <tab> b <tab> c <tab> <tab> <tab> d
Number of fields in the feed now is 6.
I greatly appreciate your help.
Thanks
vasanth
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
You can use a StringTokenizer.
Suppose ,
String s="a b c d";
You can use the StringTokenizer constructor:
StringTokeizer(String s)
Constructs a string tokenizer for the specified string. The tokenizer uses the default delimiter set, which is "\t\n\r\f": the space character, the tab character, the newline character, the carriage-return character, and the form-feed character. Delimiter characters themselves will not be treated as tokens
StringTokenizer st=new StringTokenizer(s);
while(st.hasMoreTokens())
System.out.println(st.nextToken());
The method hasMoreTokens() of the StringTokenizer returns true if there are more tokens available from this tokenizer's string s in this case.
The method nextToken() of the StringTokenizer returns the next token of the String.
The StringTokenizer will parse your String s and return the tokens a,b,c,d and in the above case it will print them as
a
b
c
d
 
reply
    Bookmark Topic Watch Topic
  • New Topic