Tilted Forum Project Discussion Community  

Go Back   Tilted Forum Project Discussion Community > Interests > Tilted Technology


 
 
LinkBack Thread Tools
Old 10-03-2004, 07:38 PM   #1 (permalink)
Insane
 
yatzr's Avatar
 
[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.
yatzr is offline  
Old 10-03-2004, 10:36 PM   #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.
oblar is offline  
Old 10-03-2004, 11:05 PM   #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."
Mavric98 is offline  
Old 10-04-2004, 10:13 AM   #4 (permalink)
Insane
 
yatzr's Avatar
 
i got it to work with the replace() function and indexOf() funtion. Thanks
__________________
Mechanical Engineers build weapons. Civil Engineers build targets.
yatzr is offline  
Old 10-04-2004, 10:17 AM   #5 (permalink)
Upright
 
Check the API docs for the String class.

You should be able to solve the core of your problem using indexOf(), substring(), and replace().
bacon is offline  
Old 10-07-2004, 02:21 PM   #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 );
}
duxx0r is offline  
 

Tags
conversion, java, simple, string


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 03:00 AM.

Tilted Forum Project

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73