• 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

Tokenizing

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All,
My file is as follows:
Name|john|
|robert|
|smith|
|ruby|
msg[0]|error: cannot insert NULL into
(the emp table) change the values
errorcode is 1111
msg is aa
|
city[0]|boston|
phone[0]|5555555555|
|8888888888|
|0|
|0|
The output should be
Name
john
robert
smith
ruby
msg[0]
error: cannot insert NULL into (the emp table) change the values errorcode is 11msg is aa
city[0]
5555555555
8888888888
0
0
what changes should i make to the code below so that if the error message spans multiple lines then all those lines should be printed as 1 token
StringBuffer StringBuf = new StringBuffer();
String line = null;
while ((line = in.readLine()) != null) {
StringBuf.append(line + "\n");
}
String cString = StringBuf.toString();
StringTokenizer tokenizer = new
StringTokenizer(cString, "\n");
while (tokenizer.hasMoreTokens()) {
currentRecord = tokenizer.nextToken();
if (currentRecord.length() > 0) {
token = new StringTokenizer(currentRecord, "|");
String s = token.nextToken().trim();
System.out.println("the string is" +s);

while (token.hasMoreTokens()) {
String testtoken=(String)token.nextToken();
System.out.println("the tetstoken is " +testtoken);
}

Thanks,
smita
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When posting code, please be sure to surround the code with the [code] and [/code] UBB Tags. This will help to preserve the formatting of the code, thus making it easier to read and understand.
Note that you can edit your own posts - just click on the icon that looks like a piece of paper.
 
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that the first thing you want to do is use "|" as the token, not "\n". Try that.
 
reply
    Bookmark Topic Watch Topic
  • New Topic