Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-17-2008, 06:17 AM
Member
 
Join Date: Jan 2008
Posts: 23
abhiN is on a distinguished road
problem with split method
Hi

i m using split methos and want to display string elements seperatly..

String quoteValues = ";;12";
String[] quote = quoteValues.split(";");
for(int i=1 ; i<quote.length ; i++)
{
if(quote[i] != "")
System.out.println(" quote--"+quote[i]);
}

but i m getting output--
quote--
quote--12

i want only to get--
quote--12

how to get..
plz reply..
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-17-2008, 06:39 AM
roots's Avatar
Moderator
 
Join Date: Jan 2008
Location: Dallas
Posts: 260
roots is on a distinguished road
Code:
if(!quote[i].equals(""))
Pointer: ==, is String a native type ??
__________________
dont worry newbie, we got you covered.

Last edited by roots : 01-17-2008 at 06:41 AM.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-17-2008, 06:45 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 839
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
The split method recognizes your token, in this case ';' and prints out the strings before or after it, if they exist - but not including the token. So after reading the first token, it looks to see surrounding strings, and finds ";12" - thus it finds another token which it can't print resulting in the undesired output. From there, I assume you know how split() operates. The pattern you're looking for is to exclude empty strings, thus:

Code:
String[] quote = quoteValues.split(";+");
Hope this helps.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-17-2008, 08:31 AM
Member
 
Join Date: Jan 2008
Posts: 23
abhiN is on a distinguished road
thanks..it works.. my simple mistake..
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to split a String using split function Java Tip java.lang 0 04-04-2008 03:39 PM
how to split a file nagaraaju New To Java 0 03-14-2008 09:45 AM
How to split a String using split function JavaBean Java Tips 0 10-04-2007 10:32 PM
Problem with sort method Albert Advanced Java 2 07-01-2007 08:12 PM
PDF Split and Merge 0.7 beta 1 JavaBean Java Announcements 0 06-24-2007 09:46 AM


All times are GMT +3. The time now is 08:26 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org