Solved

convert underscore to camelcase

Posted on 2009-07-15
4
2,000 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
[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
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

630 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