The Artima Developer Community
Sponsored Link

Java Answers Forum
testing a stringtokenizer

4 replies on 1 page. Most recent reply: Nov 8, 2002 2:53 PM by Daniel Ray

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
ben

Posts: 57
Nickname: loftty
Registered: Oct, 2002

testing a stringtokenizer Posted: Nov 8, 2002 2:39 AM
Reply to this message Reply
Advertisement
any help please
i have a text file to read in, then i have put it though a stringtokenizer with a comma as a delimeter, and i was hopeing that i can test each line to see if there is no text between each delimeter like so (hello,how,,,you)
after (how) there are three commas so i want the output to print an empty string.
any suggestions please ben


Ramu

Posts: 29
Nickname: sripoorna
Registered: Oct, 2002

Re: testing a stringtokenizer Posted: Nov 8, 2002 4:38 AM
Reply to this message Reply
hi ben
,
use the code
String str_Temp = "hello,how,,,you";
StringTokenizer stoken = new StringTokenizer(str_Temp,",");
while(stoken.hasMoreElements())
{
String str_Temp1 = stoken.nextToken();
if(str_Temp1.equals(""))
{
System.out.println("empty string found");
OR
continue;
}
else
System.out.println("non empty string found"+str_Temp1);
}

ben

Posts: 57
Nickname: loftty
Registered: Oct, 2002

Re: testing a stringtokenizer Posted: Nov 8, 2002 4:50 AM
Reply to this message Reply
thanks ramu
but i have already got that in my code
what i need to do is if the text file does not have any text between two delimeters (comma) i want it to print out the empty space what should be between two delimeters
any more suggestions
thanks ramu
ben

Daniel Ray

Posts: 53
Nickname: budoray
Registered: Oct, 2002

Re: testing a stringtokenizer Posted: Nov 8, 2002 2:53 PM
Reply to this message Reply
Try this.

Declare a global variable outside your for loop ie String pad = ""; In your if test for empty text .. when true .. say pad += " "; Add an else that resets pad = ""; Then print pad when you need to.

Note: I haven't tested to see if this will work. I'm supposed to be working <g>

Daniel Ray

Posts: 53
Nickname: budoray
Registered: Oct, 2002

Re: testing a stringtokenizer Posted: Nov 8, 2002 2:53 PM
Reply to this message Reply
Err .. outside your while loop <g>

Flat View: This topic has 4 replies on 1 page
Topic: Converting String to int Previous Topic   Next Topic Topic: How to do an applet ?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use