File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes tool to convert string A DOG RAN to A Dog Ran Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "tool to convert string A DOG RAN to A Dog Ran" Watch "tool to convert string A DOG RAN to A Dog Ran" New topic
Author

tool to convert string A DOG RAN to A Dog Ran

Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2057
Where would java programmers usually go, other than google, to look for existing, or shared codes? Like,

I need to convert

JUAN DELA CRUZ

into

Juan Dela Cruz
-------------------------------
Also, I need to convert

a string represent a whole number like 345345354

into

$345,345,354.00

-----------------------------------
any cool way to find stuff on the web for java programmers?
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

why can't you use google?
try searching on java capitalize

The jakarta commons is a great resource for shared code.
check out their StringUtils.capitalize() for the answer to your first question:
http://jakarta.apache.org/commons/lang/api/org/apache/commons/lang/StringUtils.html
Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518
Where would java programmers usually go, other than google, to look for existing, or shared codes? Like,

I need to convert

JUAN DELA CRUZ

into

Juan Dela Cruz


How about the Javadoc. [Hint: Search for "UpperCase"]

The javadoc also contains information about a class called NumberFormat that does cool stuff with numbers.
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2057
Thanks.Actually yes I can use google, but cannot use other than sun-provided classes in the company. I just didnt know what keyword to use to search.

But anyway, my work pc doesnt have access to internet. what a bummer...
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Think about how you'd like to find the letters that should be upper and the letters that should be lower. You could work one word at a time (see String.split()) or scan through the string one letter at a time (see String.charAt()).

Are you comfortable with String.substring(), toUpperCase(), toLowerCase() and so on to strip off the first letter, capitalize it, lower the rest and put them back together?

In other words, what have you tried and where are you stuck?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Tim LeMaster
Ranch Hand

Joined: Aug 31, 2006
Posts: 226
Where would java programmers usually go, other than google, to look for existing, or shared codes?


but cannot use other than sun-provided classes in the company


This is mutually exclusive you want to look for existing shared code but you can't use anything other than sun-provided classes?

my work pc doesnt have access to internet


Sounds like you need to download the Javadocs and get familar with them.
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2057
Originally posted by Stan James:
Think about how you'd like to find the letters that should be upper and the letters that should be lower. You could work one word at a time (see String.split()) or scan through the string one letter at a time (see String.charAt()).

Are you comfortable with String.substring(), toUpperCase(), toLowerCase() and so on to strip off the first letter, capitalize it, lower the rest and put them back together?

In other words, what have you tried and where are you stuck?


I havent tried any. Ill most likely split them first, capitalize the first char of each, and put them back together.

Originally posted by Tim LeMaster
:
This is mutually exclusive you want to look for existing shared code but you can't use anything other than sun-provided classes?


I was referring compiled classes with no source code. Most likely all companies are like that too. Only licensed, guaranteed compiled classes, if source is not supplied.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I havent tried any.


The ranch works at its very best when you can post some code that almost works. That way we can see exactly what you know, not insult you with things that are too basic or confuse you with things that are too advanced. So give it a shot, show us how it goes!
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
Originally posted by Jesus Angeles:

I was referring compiled classes with no source code. Most likely all companies are like that too. Only licensed, guaranteed compiled classes, if source is not supplied.


Then maybe you should have investigated the suggestion before dismissing it? Jarkarta is open source under the Apache license.
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2057
Thanks for the comments. I resorted to the possibly crude, but working code, below, based on my business requirements:

Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

That can be simplified.


And removing this check:

wouldn't hurt too.

Use a StringBuffer for appending Strings, and if you use Java 1.5, you may use the enhanced for-loop for itering:


http://home.arcor.de/hirnstrom/bewerbung
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18978
    
  40

Only because I like using regular expressions for parsing, here is an attempt at the same thing using regular expressions...



Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2057
Henry, what does that code do?

Does it follow the requirements:
- if word is 1-byte-long, dont touch
- if first char of word is not alphabetic, dont touch
- lowercase the rest of the word

(It looks like I really have to learn the regex stuff.)
[ November 11, 2006: Message edited by: Jesus Angeles ]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18978
    
  40


Does it follow the requirements:
- if word is 1-byte-long, dont touch -- Yes. It won't match.
- if first char of word is not alphabetic, dont touch -- No. Didn't know about this requirement.
- lowercase the rest of the word -- Yes

(It looks like I really have to learn the regex stuff.)


Absolutely, you should definitely learn it. Anyway, for all the requirements -- change the regex to...



Henry
[ November 11, 2006: Message edited by: Henry Wong ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: tool to convert string A DOG RAN to A Dog Ran