wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes String Values (Please Help) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String Values (Please Help)" Watch "String Values (Please Help)" New topic
Author

String Values (Please Help)

Pol Appan
Ranch Hand

Joined: Aug 26, 2004
Posts: 144
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


Never take anything for granted because you never know when you will lose it
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

I think you want to Tokenize the string (look at java.util.StringTokenizer) if I'm inderstanding your question correctly?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Pol Appan
Ranch Hand

Joined: Aug 26, 2004
Posts: 144
OK thanks , I will try that.

Cosmos
Pol Appan
Ranch Hand

Joined: Aug 26, 2004
Posts: 144
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

Joined: Aug 26, 2004
Posts: 144
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

Joined: Nov 02, 2004
Posts: 24
if you using 1.4 you could also look at the
String split method
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


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

Joined: Aug 26, 2004
Posts: 144
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

Joined: Apr 14, 2004
Posts: 10336

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

Joined: Nov 02, 2004
Posts: 24
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

Joined: Aug 26, 2004
Posts: 144
OK I didn't notice your last post in the bottom.

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

Thanks to everyone.

Cosmos
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String Values (Please Help)