Exercise: Hashtag Extractor
Problem statement
Social media platforms index hashtags to track trending topics. You receive raw text posts and must isolate the embedded hashtags to build a clean tracking string.
Task requirements
Parse the input string into individual words.
Identify words that represent hashtags.
Format the extracted hashtags into a single string separated by a comma and a space.
Return the string
"No hashtags found"if the post contains none or if the input is empty.
Constraints
Use the
Split()method to break the input string apart.Use the
StartsWith()method to check if a word begins with the#symbol.Use
string.Join()to combine the identified hashtags into the final output.Use
string.IsNullOrWhiteSpace()to safely validate that the input string contains text before processing.
Good luck trying the exercise! If you’re unsure how to proceed, check the “Solution” tab above.
Get hints
Calling
Split()without any arguments automatically splits the string by spaces.You can create a
List<string>to store the hashtags as you find them in your loop.Verify the length of your list before calling
string.Join()so you know whether to return the joined tags or the default “not found” message.
Exercise: Hashtag Extractor
Problem statement
Social media platforms index hashtags to track trending topics. You receive raw text posts and must isolate the embedded hashtags to build a clean tracking string.
Task requirements
Parse the input string into individual words.
Identify words that represent hashtags.
Format the extracted hashtags into a single string separated by a comma and a space.
Return the string
"No hashtags found"if the post contains none or if the input is empty.
Constraints
Use the
Split()method to break the input string apart.Use the
StartsWith()method to check if a word begins with the#symbol.Use
string.Join()to combine the identified hashtags into the final output.Use
string.IsNullOrWhiteSpace()to safely validate that the input string contains text before processing.
Good luck trying the exercise! If you’re unsure how to proceed, check the “Solution” tab above.
Get hints
Calling
Split()without any arguments automatically splits the string by spaces.You can create a
List<string>to store the hashtags as you find them in your loop.Verify the length of your list before calling
string.Join()so you know whether to return the joined tags or the default “not found” message.