• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

tool to convert string A DOG RAN to A Dog Ran

 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Tim LeMaster
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the comments. I resorted to the possibly crude, but working code, below, based on my business requirements:

 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Henry Wong
author
Marshal
Pie
Posts: 21446
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only because I like using regular expressions for parsing, here is an attempt at the same thing using regular expressions...



Henry
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21446
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic