Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String Values (Please Help)

 
Pol Appan
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a string value from the resultset.

I want to take values in seperate strings when there is a semicolon in the string value which comes from the resultset.

How can I do this?

Cosmos
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you want to Tokenize the string (look at java.util.StringTokenizer) if I'm inderstanding your question correctly?
 
Pol Appan
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK thanks , I will try that.

Cosmos
 
Pol Appan
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am taking the result value in a string called strval

StringTokenizer st = new StringTokenizer(strval, " ; ");

I have a count of number of delimiters by using countTokens().

My problem is how to construct the number of strings dynamically based on the count i.e number of occurences.

How to overcome this problem.

Cosmos
 
Pol Appan
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is it possible to print in new lines

for ( int i = 0; i < count; i++ ){
out.println(" \n "+new String(st.nextToken()));
}

but this is not working, though!! How can I do this. I am calling this in a JSP page.

Cosmos
 
Marco Davids II
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you using 1.4 you could also look at the
String split method
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This has no meaning in HTML. And since your JSP is generating HTML, you need to use formatting elements specific to that technology. Think about the HTML tags which will force text to appear on a new line.
 
Pol Appan
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried that but for some reason it's not working.

out.println("\n"+tokens[i]);

all the values are appearing in one single line.

Thanks

Cosmos
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Re-read my previous post, specifically the bit that says "This has no meaning in HTML."
[ January 26, 2005: Message edited by: Paul Sturrock ]
 
Marco Davids II
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cosmos

change your code to


you need to use the html tags to create the new line on yor html page
 
Pol Appan
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK I didn't notice your last post in the bottom.

I used "<BR>" to solve the problem.

Thanks to everyone.

Cosmos
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic