Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C# C# Streams and Data Processing Parsing Data Reading Line By Line

Complete the following code to split the string by spaces into an array of strings.

Please!!! will someone explain to me what i'm doing wrong?

This really shouldn't be this difficult.Split it into an array of strings. I've even tried various solutions to this.

string[] words = "The quick brown fox jumped over the lazy dog".Split(null); string[] words = "The quick brown fox jumped over the lazy dog".Split(new char[0]); string[] words = "The quick brown fox jumped over the lazy dog".Split(' '); string[] words = "The quick brown fox jumped over the lazy dog".line.Split;

Please, could someone just put my mind to rest and give me some idea?

2 Answers

Craig Fender
Craig Fender
7,605 Points

You need to pass a delimiter character to the Split method. In this case, the delimiter is a space to separate the words, so your third attempt should work as long as there is a space between the apostrophes (' '):

string[] words = "The quick brown fox jumped over the lazy dog".Split(' ');

Kevin Gates
Kevin Gates
14,854 Points

So the answer is:

Split(' ')

If you put double quotes, it fails. I'm not 100% certain if Split if quote-sensitive (" vs ' ) or if it's the Treehouse parsing logic. Either way, the correct answer is: Split(' ')