title: Sorting a string array according to a string position (C#)
body: <p>I would like to know how can i sort items of a string[] according to a specific string position. For instance i want to sort the following array by the substring " - "</p>
  
  <p>Input:  {xx - c, xxxxx - b, yyy - a, mlllll - d}</p>
  
  <p>Expected output:  {yyy - a, xxxxx - b, xx - c, mlllll - d}</p>
  
  <p>What i have so far is the following:</p>
  
  <pre><code>public string[] SortByStringPos(string[] arr, string str, bool ascending)
  {
      if (ascending)
      {
          var result = from s in arr
                       where s.Length &gt;= s.IndexOf(str)
                       orderby s[s.IndexOf(str)] ascending
                       select s;
  
          return result.ToArray();
      }
      else
      {
          var result = from s in arr
                       where s.Length &gt;= s.IndexOf(str)
                       orderby s[s.IndexOf(str)] descending
                       select s;
  
          return result.ToArray();
      }
  }
  </code></pre>
  
  <p>Can someone drop me a hint...?</p>