Solved

convert underscore to camelcase

Posted on 2009-07-15
4
1,700 Views
Last Modified: 2012-05-07
I need a method that takes in a string like "W_ACT_010_LOG_DATE" and outputs "WAct010LogDate" - which is camelcase with first letter capitalized.

What's the cleanest way to do that? (in java)
0
Comment
Question by:aturetsky
  • 2
  • 2
4 Comments
 
LVL 1

Author Comment

by:aturetsky
ID: 24862302
points increased
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 24862512
Something like:
        String s = "W_ACT_010_LOG_DATE";

        String[] atoms = s.split("_");

        StringBuilder camel = new StringBuilder();

        for (String atom : atoms) {

            if (atom.length() > 0) {

                camel.append(Character.toUpperCase(atom.charAt(0)));

            }

            if (atom.length() > 1) {

                camel.append(atom.substring(1).toLowerCase());

            }

        }

        System.out.println(camel);

Open in new window

0
 
LVL 1

Author Closing Comment

by:aturetsky
ID: 31603880
terrific, thanks
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24877088
:-)
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
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…
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…
The viewer will learn how to implement Singleton Design Pattern in Java.

758 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

21 Experts available now in Live!

Get 1:1 Help Now