Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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
15,053 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(' ')