Solved

WordUtils.capitalizeFully(String, char []) not working for me.

Posted on 2013-12-19
5
1,565 Views
Last Modified: 2013-12-19
I'm trying to capitalize each word in a string delimited by space or hyphen. I'm referencing http://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/WordUtils.html#capitalizeFully(java.lang.String, char[]), which shows as an example:

WordUtils.capitalizeFully("i aM.fine", {'.'}) = "I am.Fine"

I am trying:

 LastName = WordUtils.capitalizeFully(LastName, {' ','-'});

but I get the compile error:
importContrib.java:580: error: illegal start of expression
            LastName = WordUtils.capitalizeFully(LastName, {' ','-'});  // gets hyphenated names
                                                           ^
importContrib.java:580: error: ';' expected

Open in new window

Even if I type the example exactly as shown I still get the error. What am I doing wrong? (btw capitalizeFully() without the delimiter parameter works fine)
0
Comment
Question by:jmarkfoley
  • 2
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 39728714
LastName = WordUtils.capitalizeFully(LastName, {' ','-'});  // gets hyphenated names

Open in new window


You need

LastName = WordUtils.capitalizeFully(LastName, new char[] {' ','-'});  // gets hyphenated names

Open in new window


btw variable names in Java begin lower case and are in camel case
0
 
LVL 35

Expert Comment

by:mccarl
ID: 39728718
It should be this...
LastName = WordUtils.capitalizeFully(LastName, new char[] {' ','-'});

Open in new window

0
 
LVL 1

Author Comment

by:jmarkfoley
ID: 39728740
Thanks mccari, but CEHJ beat you to it!

CEHJ: > btw variable names in Java begin lower case and are in camel case

Yeah, I know, but this program is a port of a very large VB program and I was not about to go and change all the variable names, and possibly introduce lots of errors, just because of convention.

Thanks for the fix! That did the trick.
0
 
LVL 1

Author Closing Comment

by:jmarkfoley
ID: 39728744
I thought about trying that, but figured the function prototype would have cast it correctly. Should have tried it!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39728752
Yeah, I know, but this program is a port of a very large VB program and I was not about to go and change all the variable names, and possibly introduce lots of errors, just because of convention.
You could always use WordUtils on the source ;)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question