Solved

convert underscore to camelcase

Posted on 2009-07-15
4
1,875 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

Technology Partners: 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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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…

679 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