DEV Community

Discussion on: Daily Challenge #188 - Break camelCase

Collapse
 
vidit1999 profile image
Vidit Sarkar

C++ solution

string ccbreaker(string camelCased){
    string nonCamelCased = ""; // string that is ragular one
    for(char c : camelCased){
        // whenever a upper case letter is encountered first add a space
        // and then add its lower case version
        if(c <= 90 && c >= 65){
            nonCamelCased += " ";
            nonCamelCased += char(c+32);
        }
        // if not uppercase then simply add it
        else{
            nonCamelCased += c;
        }
    }
    return nonCamelCased;
}