Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get the characters from String.

 
hariharan jayaprakash
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49444
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you not want to use the ready-made methods in the String class?
 
hariharan jayaprakash
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And when you looked through the methods of the String class which seemed useful?
 
hariharan jayaprakash
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you show us your code? Because that should work.
 
Nico Van Brandt
Ranch Hand
Posts: 70
IntelliJ IDE Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Wouter Oet: thanks for your concern, i tried like this, can you check?..

 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2700
IntelliJ IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Than just use String.split() and access the third element of the array returned by that method.
 
hariharan jayaprakash
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah its working as expected.. by accessing third element from the array directly...

thanks to everyone..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic