c# - How can i sort a List<string> according to the numbers in each string in each index? -
Finally in the thread list I have for example:
  1 Hello world < / Code> 
Then I have in Index 2:
  33 Hello  
Then I have 3 in index: / P>
  76 Hello  
In index 4:
  2 good  
 numbers     and then numbers are part of the string they are not int.   This is the method which lists:  1 33 76 2 > Each index is a part of the string.   1 Hello world  is a string I want to sort the list according to the numbers so that this example should be:  
  1 Hello World 2. good 33. hello 76. hello   
  public string GetResponsers (string content) {string responser = ""; & Lt; String & gt; Thread list = new list & lt; String & gt; (); Int f = 0; Int startPos = 0; While (true) {string firstTag = " gt; String end tag = "& amp; n"; F = contents.IndexOf (first tag, startPos); If (f == -1) {break; } Int G = Content Index (last tag, f); StartPos = G + Last tag. Responder = Content.Substring (f + 22, g - f - 22); ThreadList.Add (responser); } Return Representative; }  
I think I see what you want ...
  yourList.OrderBy (str = & gt; {var match = Regex.Match (str, @ "^ ([- +]? \ D +)"); Return match. Success? Int.Parse (match group [1]. Value): int.MaxValue;});    This will be an  IEnumerable & lt; by the value of the integer that appears at the beginning of the string. String & gt;  will order. Entries without number will be kept in the end. 
 Edit: If you want to be ordered that variable  yourList , then you have to reassign it: 
  YourList = yourList Orderbie (str = => {match} = match regex (str, @ "^ ([- +]? \ D +)"); Return match. Success? Int.Parse (match group [1] .will) : Int.MaxValue;}) .Oolist ();   
Comments
Post a Comment