You must Sign In to post a response.
  • Category: LINQ

    Linq not working in html tag removed String

    I have a C# list in which one property has html string as below.
    List<item> test = new List<item>;
    test.Subject = "<div><externalclass=....><p>Original Text HERE</p></div>

    I removed the html tags using the code
    test[i].Subject = Regex.Replace(test[i]].Subject, @"<(.|\n)*?>", string.Empty)

    After removal i have the property in list item as:
    test.Subject="Original Text HERE"

    Now am using linq to sort the subject by descending/ascending but the values are not sorting in the order. Am not sure why. Please help

    var output = test.OrderByDescending(x=>x.Subject.Trim()).ToList();
    Also tried the below
    var output = test.OrderByDescending(x=>x.Subject.Trim()).Select(x=>x).ToList();

    All other properties in the list are sorting properly but the property for which i removed html tags are not sorting. Could you please let me know what am missing
  • #759592
    There are hidden chars after replacing using the below regex:

    test[i].Subject = Regex.Replace(test[i]].Subject, @"<(.|\n)*?>", string.Empty)

    So additional 1 line of regex should be used to replace special chars. The additional 1 line is:

    Regex. Replace(test[i]].Subject, @"[^\x20-\x7F]", string.Empty)

    Now the sorting perfectly worked for me!!!!

  • #759598

    better u have to use the methods and in code behinds u use the linq querry and returns to the clients. it will work for uu..


  • Sign In to post your comments