Given a sentence, task is to remove spaces from the sentence and rewrite in Snake case. It is a style of writing where we replace spaces with underscore and all words begin with small letters.
Input : I got intern at geeksforgeeks Output : i_got_intern_at_geeksforgeeks Input : Here comes the garden Output : here_comes_the_garden
Simple solution : First method is to traverse sentence and one by one replace spaces by underscores and changing case of first character to small letter. It takes O(n*n) time.
Efficient solution : We traverse given string, while traversing we replace space character with underscore and whenever we encounter non-space letter, we change that letter to small.
Below is the code implementation :
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- gOOGLE cASE of a given sentence
- Camel case of a given sentence
- Sentence Case of a given Camel cased string
- Lower case to upper case - An interesting fact
- Frequency of smallest character in first sentence less than that of second sentence
- Reverse the Sentence using Stack
- Calculate the difficulty of a sentence
- Split a sentence into words in C++
- Check if a word is present in a sentence
- Count palindrome words in a sentence
- Remove all the palindromic words from the given sentence
- Permute a string by changing case
- Case-specific Sorting of Strings
- String in Switch Case in Java
- Remove consecutive alphabets which are in same case
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.