• Post Reply Bookmark Topic Watch Topic
  • New Topic

In need of a method to convert to Mixed Case  RSS feed

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
This is probably one of the eternal questions, and probably a buggy idea, but I am in need a standard Mixed Case converter.
Basically I have some strings that are in al "UPPERCASE LIKE THIS" and I need to conver them in a method to be "Uppercase Like This", I don't have any complicated rules. I just need each word to start in caps and have all the rest of the letters in small case.
If anybody has this method laying around, please share it with me!
 
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is probably one of the eternal questions, and probably a buggy idea, but I am in need a standard Mixed Case converter.
Actually I don't think I've seen this question before. It's not too difficult with regular expressions though:

I deliberately avoided the appendReplacement() method because it does some funny things if the replacement string has $ or \ in it. As written, you would've be safe with appendReplacement() since the pattern won't match any of those characters anyway. But you may find it necessary to modify the pattern for some reason, depending on how you want to handle any special cases in your inputs. I've found it's easier to avoid appendReplacement() at the cost of a couple extra lines of code, as it saves headaches later.
[ January 24, 2004: Message edited by: Jim Yingst ]
 
Paul Duer
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Man, I feel so stupid. I forgot to mention this is on a WAS 4.0.2 server, so I won't have access to Regular Expressions.
I know Jim probably doesn't want to do all the work again, any body else have any ideas?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's an alternate implementation. (Same tests apply.)
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Paul Duer
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you both! All three of the solutions presented are very well done and more than meet my need.
It's really nice to have a forum to get input from advanced developers such as you all.
Thanks again!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!