• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Taking Values From a String

 
naro pad
Ranch Hand
Posts: 58
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I pass a String parameter where can has value of this type:

"2.ACSC344,5.ACSC345,8.ACSC456"

I want somehow to read from this String and save it to hashtable.When I find the number(before dot) to save it as the key and when finding the code(after dot)save as the value of the key and I want to loop until all are saved.How can I do that if it's possible?
[ June 08, 2008: Message edited by: panayiotis panayiotou ]
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using String's split() method.
 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keep in mind that this method uses regular expression, and . is a special character. You'll need to escape it: "\\."
 
Shashi Kala
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To escape dot why the need of two slash symbols(\\). Is using one slash is not enough??

Sorry in case if this question is silly.
 
Rodrigo Lopes
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The slash is also a special character. Then you need two slashes to escape a slash
 
naro pad
Ranch Hand
Posts: 58
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all of you for the replies...but because I'm a beginner can anyone provide me with an example or reference please?
 
Rodrigo Lopes
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you already tried something, after those clues?
 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like Rodrigo said, \ is a special character. The regular expression is just \. but you will need to escape that \ too.
 
naro pad
Ranch Hand
Posts: 58
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot...It's working.I have do it like this:
 
ibrahim uzan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This one is also be the solution..

[edit]Add code tags. CR[/edit]
[ September 17, 2008: Message edited by: Campbell Ritchie ]
 
Campbell Ritchie
Sheriff
Pie
Posts: 49361
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch, ibrahim uzan.

By the way: Most people would use a HashMap nowadays rather than Hashtable; it is more efficient.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic