Results 1 to 5 of 5
Thread: Extracting Double from String?
- 03-19-2011, 03:21 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 5
- Rep Power
- 0
Extracting Double from String?
Alright guys let's say I have a String:
"\u00A3 3.39 per Unit"
the String displays cost of a product and what I need to do next is get the "3.39" part of the String and continue working with that. How can I extract that number? I was thinking about using a loop with charAt(); Method and just parse it to double but it would extract 003 in front of that String as well since it's a code I must use to get GBP symbol. so does anyone have an elegant solution to this?
should I use loop with charAt();
substring(3);
and then parse?
or does anyone have any other solutions?
TYVM!Last edited by mutagen; 03-19-2011 at 05:41 PM. Reason: Complete.
- 03-19-2011, 04:45 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,609
- Rep Power
- 5
Might be overkill for something like this, but I'll post anyways:
Lesson: Regular Expressions (The Java™ Tutorials > Essential Classes)
If you expect the strings to remain constant, just split on whitespace or use a StringTokenizer, take the string with the number and use Double.parseDouble to get the double value
- 03-19-2011, 05:38 PM #3
And if you do need to use regex, there's another, more detailed tutorial on this site:
Regular-Expressions.info - Regex Tutorial, Examples and Reference - Regexp Patterns
db
- 03-19-2011, 05:42 PM #4
Member
- Join Date
- Mar 2011
- Posts
- 5
- Rep Power
- 0
Thanks guys!
- 03-20-2011, 04:30 AM #5
Senior Member
- Join Date
- Dec 2010
- Posts
- 165
- Rep Power
- 3
Similar Threads
-
String to double HELP please!
By zhen1337 in forum New To JavaReplies: 33Last Post: 02-08-2011, 09:30 AM -
String to double errors
By bigvanilla in forum New To JavaReplies: 9Last Post: 12-05-2010, 08:42 AM -
Problem extracting items from a string with separators
By PepsiColaMola in forum New To JavaReplies: 3Last Post: 04-24-2009, 08:30 PM -
Extracting words from a string using delimiters
By toad in forum New To JavaReplies: 4Last Post: 07-07-2008, 01:32 PM -
program help: Extracting words from a string
By toad in forum New To JavaReplies: 1Last Post: 11-04-2007, 06:39 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks