Solved

convert underscore to camelcase

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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 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…
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…

776 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