Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Taking Values From a String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Taking Values From a String" Watch "Taking Values From a String" New topic
Author

Taking Values From a String

naro pad
Ranch Hand

Joined: May 07, 2008
Posts: 58

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

Joined: Aug 31, 2004
Posts: 11343

Try using String's split() method.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Keep in mind that this method uses regular expression, and . is a special character. You'll need to escape it: "\\."


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Shashi Kala
Ranch Hand

Joined: Jan 27, 2008
Posts: 46
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

Joined: Feb 29, 2008
Posts: 119
The slash is also a special character. Then you need two slashes to escape a slash
naro pad
Ranch Hand

Joined: May 07, 2008
Posts: 58

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

Joined: Feb 29, 2008
Posts: 119
Have you already tried something, after those clues?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Like Rodrigo said, \ is a special character. The regular expression is just \. but you will need to escape that \ too.
naro pad
Ranch Hand

Joined: May 07, 2008
Posts: 58

Thanks a lot...It's working.I have do it like this:
ibrahim uzan
Greenhorn

Joined: Sep 17, 2008
Posts: 2


This one is also be the solution..

[edit]Add code tags. CR[/edit]
[ September 17, 2008: Message edited by: Campbell Ritchie ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38040
    
  22
Welcome to JavaRanch, ibrahim uzan.

By the way: Most people would use a HashMap nowadays rather than Hashtable; it is more efficient.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Taking Values From a String
 
Similar Threads
IP Address Validation
Splitting string around "." ?
need to encode a string
Getting the Key from a properties file
using two properties files in struts