Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Challenge: Clean Up User Input | Text Formatting & Manual Parsing
C# Strings & Text Processing

bookChallenge: Clean Up User Input

Aufgabe

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.

Lösung

Program.cs

Program.cs

copy
1234567891011121314151617181920212223242526272829
using 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 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.

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 u with you and standalone r with are (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 u or r at the start or end.
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 6
single

single

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

Suggested prompts:

Can you provide an example input and expected output for the function?

What programming language should the function be written in?

Do you want the function to handle punctuation as well?

close

bookChallenge: Clean Up User Input

Swipe um das Menü anzuzeigen

Aufgabe

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.

Lösung

Program.cs

Program.cs

copy
1234567891011121314151617181920212223242526272829
using 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 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.

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 u with you and standalone r with are (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 u or r at the start or end.
Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 6
single

single

some-alt