Challenge: Clean Up User Input
Завдання
Swipe to start coding
Write a function that takes a sentence and returns a cleaned, formatted version.
- Remove extra spaces from the beginning and end of the sentence.
- Replace all sequences of multiple spaces between words with a single space.
- Replace every standalone "u" with "you" and "r" with "are", only when they appear as whole words.
- Capitalize the first letter of the sentence and make all other letters lowercase.
Рішення
Program.cs
1234567891011121314151617181920212223242526272829using System; namespace ConsoleApp { public class Program { public static string CleanUpSentence(string sentence) { // Write your code here return ""; } public static void Main(string[] args) { string messy = " hey u r awesome! "; string cleaned = CleanUpSentence(messy); Console.WriteLine(cleaned); string messy2 = " u are the best "; string cleaned2 = CleanUpSentence(messy2); Console.WriteLine(cleaned2); string messy3 = "r u coming to the party "; string cleaned3 = CleanUpSentence(messy3); Console.WriteLine(cleaned3); } } }
Write a function that takes a sentence and returns a cleaned, formatted version.
- Remove extra spaces from the beginning and end of the sentence;
- Replace all sequences of multiple spaces between words with a single space;
- Replace every standalone
uwithyouandrwithare, only when they appear as whole words; - Capitalize the first letter of the sentence and make all other letters lowercase.
Unit Test Checklist
- The function removes all leading and trailing spaces from the input;
- The function replaces sequences of multiple spaces between words with a single space;
- The function replaces standalone
uwithyouand standalonerwithare(case sensitive); - The function capitalizes only the first letter of the output sentence and makes the rest lowercase;
- The function returns the correct cleaned string for sentences containing only
uorrat the start or end.
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 2. Розділ 6
single
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Чудово!
Completion показник покращився до 4.76
Challenge: Clean Up User Input
Свайпніть щоб показати меню
Завдання
Swipe to start coding
Write a function that takes a sentence and returns a cleaned, formatted version.
- Remove extra spaces from the beginning and end of the sentence.
- Replace all sequences of multiple spaces between words with a single space.
- Replace every standalone "u" with "you" and "r" with "are", only when they appear as whole words.
- Capitalize the first letter of the sentence and make all other letters lowercase.
Рішення
Program.cs
1234567891011121314151617181920212223242526272829using System; namespace ConsoleApp { public class Program { public static string CleanUpSentence(string sentence) { // Write your code here return ""; } public static void Main(string[] args) { string messy = " hey u r awesome! "; string cleaned = CleanUpSentence(messy); Console.WriteLine(cleaned); string messy2 = " u are the best "; string cleaned2 = CleanUpSentence(messy2); Console.WriteLine(cleaned2); string messy3 = "r u coming to the party "; string cleaned3 = CleanUpSentence(messy3); Console.WriteLine(cleaned3); } } }
Write a function that takes a sentence and returns a cleaned, formatted version.
- Remove extra spaces from the beginning and end of the sentence;
- Replace all sequences of multiple spaces between words with a single space;
- Replace every standalone
uwithyouandrwithare, only when they appear as whole words; - Capitalize the first letter of the sentence and make all other letters lowercase.
Unit Test Checklist
- The function removes all leading and trailing spaces from the input;
- The function replaces sequences of multiple spaces between words with a single space;
- The function replaces standalone
uwithyouand standalonerwithare(case sensitive); - The function capitalizes only the first letter of the output sentence and makes the rest lowercase;
- The function returns the correct cleaned string for sentences containing only
uorrat the start or end.
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 2. Розділ 6
single