Solved

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

Posted on 2013-12-19
5
1,596 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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…

749 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