title: Trim String value with particular pattern in C#.NET
body: <p>I have a string which is 900-1000 characters long.
  the pattern string follows is</p>
  
  <blockquote>
    <p>"Number:something,somestringNumber:something,somestring" </p>
  </blockquote>
  
  <p>and so on example string: </p>
  
  <blockquote>
    <p>"23:value,ordernew14:valueagain,orderagain"</p>
  </blockquote>
  
  <p>the requirement is whenever it crosses more than 1000 characters, I have to remove first 500 characters. and then if doesnot starts with Number, i have to remove characters until I reach to point where first character is digit</p>
  
  <pre><code>sortinfo = sortinfo.Remove(0, 500);
  sortinfo = new string(sortinfo.SkipWhile(c =&gt; !char.IsDigit(c)).ToArray());
  </code></pre>
  
  <p>I am able to do this with the help of above code</p>
  
  <p>In the above example if i give remove 5 characters output will be </p>
  
  <blockquote>
    <p>14:valueagain,orderagain</p>
  </blockquote>
  
  <p>which is perfectly fine.
  but if the string has value : </p>
  
  <blockquote>
    <p>23:value,or3dernew14:valueagain,orderagain</p>
  </blockquote>
  
  <p>and remove 5 characters, output is</p>
  
  <blockquote>
    <p>3dernew14:valueagain,orderagain</p>
  </blockquote>
  
  <p>and requirement is to have </p>
  
  <blockquote>
    <p>14:valueagain,orderagain </p>
  </blockquote>
  
  <p>and hence its breaking everything as it is not in correct format.
  please help me how can I do this</p>
  
  <p>my full code</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          string str;
          str=TrimSortInfo("23:value,ord4er24:valueag4ain,order6again15:value,order"); // breaking value
          //str = TrimSortInfo("23:value,order24:valueagain,orderagain15:value,order"); //working value
          Console.WriteLine(str);
          Console.ReadLine();
  
      }
  
      static string TrimSortInfo(string sortinfo)
      {
          if (sortinfo.Length &gt; 15)
          {
              sortinfo = sortinfo.Remove(0, 15);
              sortinfo = new string(sortinfo.SkipWhile(c =&gt; !char.IsDigit(c))
                           .ToArray());
              return sortinfo;
          }
          return sortinfo;
      }
  }
  </code></pre>