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 :
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Convert camel case string to snake case in Java
- Convert Snake Case string to Camel Case in Java
- Camel case of a given sentence
- gOOGLE cASE of a given sentence
- Sentence Case of a given Camel cased string
- Frequency of smallest character in first sentence less than that of second sentence
- Lower case to upper case - An interesting fact
- Check a given sentence for a given set of simple grammer rules
- Find the word from a given sentence having given word as prefix
- Remove all the palindromic words from the given sentence
- Print given sentence into its equivalent ASCII form
- Java program to count the characters in each word in a given sentence
- Find the word with most anagrams in a given sentence
- Extract and print words separately from a given Camel Case string
- Calculate the difficulty of a sentence
- Sentence Palindrome (Palindrome after removing spaces, dots, .. etc)
- Sums of ASCII values of each word in a sentence
- Convert the ASCII value sentence to its equivalent string
- Java program to swap first and last characters of words in a sentence
- Convert a sentence into its equivalent mobile numeric keypad sequence
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.