Results 1 to 7 of 7
Thread: Manipulating strings
- 04-03-2011, 03:54 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 25
- Rep Power
- 0
-
You need to give us the specific rules of your desired transformation. One example isn't enough to be able to guess your rules.
- 04-03-2011, 05:32 AM #3
subString is going to probably do what you are looking for. You can define a beginning and end index(if needed) and 'chop' the string down to what you want. You can also use indexOf and pass in a token if you want to manipulate your string based on the presence/position of some character or pattern
- 04-03-2011, 06:50 AM #4
Member
- Join Date
- Feb 2011
- Posts
- 25
- Rep Power
- 0
I have three variables which are being passed to an array. I want them to become doubles and so I need to get rid of the pieces of the string which cannot convert to a double. So I have "$200,000" and "5.75%" and "7 years" as strings. I want to convert them to doubles to do math with them. So I want the strings to become these doubles 200000, and 5.75 and 7. Hope that helps!
- 04-03-2011, 06:58 AM #5
Senior Member
- Join Date
- Dec 2010
- Posts
- 165
- Rep Power
- 3
you can use replaceAll() or replace().
check the documentation for replaceAll(). I write only from memory.Java Code:String myString = "$200,000"; System.out.println ( myString.replaceAll( "[$,]", "" );
- 04-03-2011, 07:22 AM #6
So you want to retain all characters that are digits, and exclude the rest. Read the documentation for String#replaceAll(...) as hinted by JavaHater, along with the Pattern API.
Some valuable lessons on using regex can be found here:
Regular-Expressions.info - Regex Tutorial, Examples and Reference - Regexp Patterns
dbLast edited by DarrylBurke; 04-03-2011 at 07:26 AM.
- 04-07-2011, 09:45 PM #7
Member
- Join Date
- Feb 2011
- Posts
- 25
- Rep Power
- 0
Similar Threads
-
Picture manipulating help
By evolutiongsr8 in forum New To JavaReplies: 0Last Post: 03-26-2011, 06:47 AM -
Manipulating BufferedImage
By ace_quorthon in forum Java 2DReplies: 1Last Post: 01-08-2011, 04:35 PM -
assigning strings and int from a file and then manipulating the data
By NDBASS in forum EclipseReplies: 1Last Post: 11-04-2010, 02:42 PM -
Manipulating URLs
By TheFlying_Boy in forum NetworkingReplies: 0Last Post: 08-03-2009, 05:01 PM -
Manipulating XML
By JosephMConcepcion in forum XMLReplies: 2Last Post: 04-26-2009, 12:01 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks