title: Get array of words from a string
body: <p>I am working on an requirement where I need to get all the words from a string into an array.
  A 'word' is described as any sequence of non-space charachters.
  There can be any number of whitespace charachters present in the string.</p>
  <p>Input Examples :</p>
  <pre><code>&quot;  Hello World!!  &quot;
  &quot;Hello World!!&quot;
  &quot;  Hello       World!!    &quot;
  </code></pre>
  <p>In all above cases the output should be [&quot;Hello&quot;,&quot;World!!&quot;]</p>
  <p>Now I have tried to solve the example myself and have below code :</p>
  <pre><code>public string[] GetWords(string s)
     {
          s=s.Trim();
          while(s.Contains(&quot;  &quot;))
          {
              s = s.Replace(&quot;  &quot;, &quot; &quot;);
          }
  
          string[] input=s.Split(' ');
          return input;
     }
  </code></pre>
  <p>I am getting correct result using the above code. My concerns is there any way the code can be made clean or more optimized than it currently is.</p>