none
Removing certain strings from a list of strings that comes from a table. RRS feed

  • Question

  • Hello,

    I need to remove certain strings from a list of strings.  I am getting both these list of strings from a table.

    I was getting the strings that need to be removed from this linq statement:

    var filterListVar = (from myrow in mReport.ReportDataSet.Tables["tblLUTPlantPackagingTimes"].AsEnumerable()

    where (string)myrow["PlantID"] =="PlantID"

    select myrow["PackagingTimes"]);

     

    The list that contains all the words I am getting like:

     

    var wholeListVar = (from myrow in mReport.ReportDataSet.Tables["tblERPPackages"].AsEnumerable()

    select myrow["PackageCode"]);

     

    I was trying to make a 3rd linq statement that returns all the words in the wholeListVar except for the words that match the same words in the filterListVar.  But I was not having much success.  How can you do this?  Or better yet...how can I make this just 1 Linq statement that would do all of that?

    Friday, September 24, 2010 6:28 PM

Answers

All replies

  • Hi Lavagin,

    You could use Enumerable.Except method (System.Linq) to produce the set difference of two sequences, something like this:

    var result = wholeListVar.Except(filterListVar);


    or

     

    var result = (from myrow in mReport.ReportDataSet.Tables["tblERPPackages"].AsEnumerable()
    select myrow["PackageCode"]).Except((from myrow in mReport.ReportDataSet.Tables["tblLUTPlantPackagingTimes"].AsEnumerable()

    where (string)myrow["PlantID"] =="PlantID"

    select myrow["PackagingTimes"]));

    If you would like to know something more about the Enumerable.Except method , please refer to :
    http://msdn.microsoft.com/en-us/library/system.linq.enumerable.except.aspx

    Best regards,

    Alex Liang

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Lavagin Monday, September 27, 2010 5:29 PM
    Monday, September 27, 2010 3:14 AM
    Moderator
  • Hi Alex (again)  :)

     

    I was wondering how you compared two lists together like that in Linq.  Thanks for showing me.

     

    ---Dave

    Monday, September 27, 2010 5:29 PM
  • Hi Dave,

    You mean compare two lists of string ? If the elements of the two lists are same,  then they are equal ? Could you please clarify this ?

    Best regards,
    Alex Liang
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com 


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, September 28, 2010 2:09 AM
    Moderator