aspose file tools*
The moose likes Beginning Java and the fly likes Get the characters from String. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Get the characters from String." Watch "Get the characters from String." New topic
Author

Get the characters from String.

hariharan jayaprakash
Ranch Hand

Joined: Sep 09, 2010
Posts: 62
I have a String value like this

String a = "ab::cd::ef::gh::ij"


I need to iterate tat string and pick tat "ef" values from tat string..

values("ab,cd,ef,gh,ij") is dynamically generated string values..

how can i achieve tat?...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36599
    
  16
Do you not want to use the ready-made methods in the String class?
hariharan jayaprakash
Ranch Hand

Joined: Sep 09, 2010
Posts: 62
hmm yeah like, i want to pickup the character symbols which is enclosed in my string("::") . so that while iterating, then i need to get tat middle value(""ef) of that string...

am i clear?...
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

And when you looked through the methods of the String class which seemed useful?


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
hariharan jayaprakash
Ranch Hand

Joined: Sep 09, 2010
Posts: 62
I tried using split() method, for making the string to split with the symbol("::")enclosed in my string values.

but i couldn't achieve..
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Could you show us your code? Because that should work.
Nico Van Brandt
Ranch Hand

Joined: Mar 31, 2011
Posts: 66



Oracle Java SE6 Certified Programmer
Oracle Java EE5 Certified Web Component Developer
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

@Nico: Please don't provide total solutions. The topic starter won't learn a thing from that. Like the forums description says:
We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.
hariharan jayaprakash
Ranch Hand

Joined: Sep 09, 2010
Posts: 62
Thanks Nico

but the values ab::cd:ef::gh::ij,


The values in bold are dynamically generated, In tat case, it won't work?.. rite?...






hariharan jayaprakash
Ranch Hand

Joined: Sep 09, 2010
Posts: 62
@Wouter Oet: thanks for your concern, i tried like this, can you check?..

Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Let me ask you another question: why do you want "ef"? Is it because it is the third element? Or because it is the middle element?
hariharan jayaprakash
Ranch Hand

Joined: Sep 09, 2010
Posts: 62
I want to get the third element, not like middle... and tat element size is not constant values... it may be "efgh" anything..
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Than just use String.split() and access the third element of the array returned by that method.
hariharan jayaprakash
Ranch Hand

Joined: Sep 09, 2010
Posts: 62
yeah its working as expected.. by accessing third element from the array directly...

thanks to everyone..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get the characters from String.
 
Similar Threads
parsing interview question
Servlet Mapping
How to align mutliple columns properly using print?
False Coin
JAVA StringBuffer line breaking