?
Solved

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

Posted on 2013-12-19
5
Medium Priority
?
1,704 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 2000 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 36

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month11 days, 4 hours left to enroll

770 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