Python program to convert a sentence into Camel, Pascal, Snake and Kebab Case.
Convert a sentence into 4 different Case-Styles
4 commanly used Case-Styles are :-
1. camelCase : this case combines words by capitalizing all words following the first word and removing the space.
2. PascalCase : this case combines words by capitalizing all words (even the first word) and removing the space
3. snake_case : this case combines words by replacing each space with an underscore (_) ; and in the all caps version, all letters are capitalized.
4. kabeb-case : this case combines words by replacing each space with a dash (-).
Approach :
1. For the camelCase we create a new variable to store the new sentence and then using a loop( here I'm using a while loop) extract each character and check if it is a whitespace(' ') then to the new variable add the corresponding next character in upper case and increase the value of the iterator by adding 2. Continue adding each character from the original sentence to the variable.
2. For the PascalCase we simply change the 0th character from the camelCase string to uppercase and add the rest of the camelCase string from 1st to the last index as it is.
3. For the snake_case we just use the .replace() to replace the whitespaces(' ') with an underscore('_').
4. For the kabeb-case we use the .replace() to replace the whitespaces(' ') with a dash('-').
Program Code :
Sample Output :
Output 1 :
Output 2 :
Comments
Post a Comment