I would assume this would be very easy but I'm not seeing it listed anywhere. How can I change a string variable to read something else? For instance I want to take this string "$200,000" and convert it to "200000". How can I do this in Java? Thanks for the help!
You need to give us the specific rules of your desired transformation. One example isn't enough to be able to guess your rules.
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
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!
you can use replaceAll() or replace().
check the documentation for replaceAll(). I write only from memory.
String myString = "$200,000";
System.out.println ( myString.replaceAll( "[$,]", "" );
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
Thanks for the help, sorry it took me a while to respond! ;)