![]() |
![]() |
#1 (permalink) |
Insane
|
[JAVA] simple string conversion
i need a method that will take a string like
blah_blah_blah_(stuff).stuff and turn it into "blah blah blah" with the quotes and everything. I can't use anything based on the positions of the unwanted characters because they're different for each line (except for the extension which isn't always 3 characters anyway). So basically, I need to seek out underscores and change them to spaces, and cut the string short at the first parentheses. I can just concatonate (sp?) the quotes in there later. Thanks for any help in advance.
__________________
Mechanical Engineers build weapons. Civil Engineers build targets. |
![]() |
![]() |
#2 (permalink) |
Über-Rookie
Location: No longer, D.C
|
My advice would be to check out the Regex api. Don't know it off the top of my head, but you can easily do that sort of replace with Regular Expressions.
its a bit late to give a more indepth answer, but I will see what i can come up with tomorrow, when I may be a little more functional. |
![]() |
![]() |
#3 (permalink) |
Tilted
Location: I am not living.
|
Doesn't java have a replace() funtion? Or if you need to dump the rest after the last underscore there should be like an instr() function you could use in conjunction with a simple loop to solve your problem.
__________________
"Hope is for people that don't stand a chance." |
![]() |
![]() |
#6 (permalink) |
Upright
Location: Brisbane
|
I think this way looks cleaner...
import java.util.regex.*; Matcher matches = null; if ((matches = Pattern.compile("^(\\d{1,2})[\\/.-](\\d{1,2})").matcher(input)).matches()) { System.out.println("First Value: "+Integer.parseInt(matches.group(1)) ); System.out.println("Second Value: "+Integer.parseInt(matches.group(2))-1 ); } |
![]() |
Tags |
conversion, java, simple, string |
|
|