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
Solved

convert underscore to camelcase

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
map related example 6 55
reverse digits of a number using for loop 5 52
expectj telnet failing 5 45
iterator/ListIterator approach 17 39
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…
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…
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…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

828 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