Solved

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

Posted on 2013-12-19
5
1,456 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
Comment Utility
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
Comment Utility
It should be this...
LastName = WordUtils.capitalizeFully(LastName, new char[] {' ','-'});

Open in new window

0
 
LVL 1

Author Comment

by:jmarkfoley
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 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…
The viewer will learn how to implement Singleton Design Pattern in Java.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now