Solved

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

Posted on 2013-12-19
5
1,626 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

734 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