• (2 Pages)
  • +
  • 1
  • 2

Using LINQ Requires .NET 3.5 & above Rate Topic: -----

#1 AdamSpeight2008   User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

Posted 28 August 2008 - 01:29 AM

Requires .Net Framework 3.5

What is LINQ?
Language INtegrated Query

What does it do?
Lets you use SQL queries on Objects, mainly arrays IEnumerable(Of T).

Simple example
-Find all of the words the contain AR and put them in Alphabetical order.
Dim words() As String = {"DOG", "CARROT", "APPLE", "AARDVARK", "ELEPHANT"}
Dim TheLINQ_Matches As IEnumerable(Of String)
TheLINQ_Matches = From TheWord As String In words Where TheWord Like "*AR*" Order By TheWord Ascending
For Each Word As String In TheLINQ_Matches
 Console.WriteLine(Word)
Next



It can be used on class objects too.
For example this one which is handles date events.
Public Class DatumEvent

    Private mStartTime As DateTime
    Private mJStart As Double
    Public Property StartTime() As DateTime
        Get
            Return mStartTime
        End Get
        Set(ByVal value As DateTime)
            mStartTime = value
            mJStart = JDate(mStartTime)
        End Set
    End Property
    Private mFinishTime As DateTime
    Private mJFinish As Double

    Public Property FinishTime() As DateTime
        Get
            Return mFinishTime
        End Get
        Set(ByVal value As DateTime)
            mFinishTime = value
            mJFinish = JDate(mFinishTime)

        End Set
    End Property

    Public ReadOnly Property StartTime_Julian() As Double
        Get
            Return mJStart
        End Get
    End Property

    Public ReadOnly Property FinishTime_Julian() As Double
        Get
            Return mJFinish
        End Get
    End Property

    Public ReadOnly Property Delta_TimeSpan() As TimeSpan
        Get
            Return mFinishTime.Subtract(mStartTime)
        End Get
    End Property

    Public ReadOnly Property Delta_Julian() As Double
        Get
            Return mJFinish - mJStart
            'JDate(mFinishTime) - JDate(mStartTime)
        End Get
    End Property

    Private mEventText As String
    Public Property EventText() As String
        Get
            Return mEventText
        End Get
        Set(ByVal value As String)
            mEventText = value
        End Set
    End Property
    Private mEventColor As System.Drawing.Color

    Public Property EventColor() As System.Drawing.Color
        Get
            Return mEventColor
        End Get
        Set(ByVal value As System.Drawing.Color)
            mEventColor = value
        End Set
    End Property

    Private Function JDate(ByRef thisdate As DateTime) As Double
        Dim a As Double = Math.Floor((14 - thisdate.Month) / 14)
        Dim y As Double = thisdate.Year + 4800 - a
        Dim m As Double = thisdate.Month + (12 * a) - 3
        Dim jdn As Double = 0
        jdn = thisdate.Day + Math.Floor(((153 * m) + 2) / 5) + (365 * y) + Math.Floor(y / 4) - Math.Floor(y / 100) + Math.Floor(y / 400) - 32045
        jdn += ((thisdate.Hour - 12) / 24) + (thisdate.Minute / 1440) + (thisdate.Second / 86400)
        Return jdn
    End Function

    Public Sub New(ByRef Start As DateTime, ByRef Finish As DateTime, ByRef Text As String,ByRef color As System.Drawing.Color)
        StartTime = Start
        FinishTime = Finish
        EventText = Text
        EventColor = color
       End Sub
End Class



Utilized by the following program.
Public Class Form1
    Dim TheEvents As New List(Of DatumEvent)
  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        TheEvents.Add(New DatumEvent(New Date(2008, 8, 24, 7, 0, 0), New Date(2008, 8, 24, 15, 0, 0), "Work Shift", System.Drawing.Color.Red))
        TheEvents.Add(New DatumEvent(New Date(2008, 8, 26, 15, 0, 0), New Date(2008, 8, 26, 23, 0, 0), "Work Shift", System.Drawing.Color.DarkBlue))
        TheEvents.Add(New DatumEvent(New Date(2008, 8, 30, 15, 0, 0), New Date(2008, 8, 30, 23, 0, 0), "Work Shift", System.Drawing.Color.Yellow))
        TheEvents.Add(New DatumEvent(New Date(2008, 8, 31, 15, 0, 0), New Date(2008, 8, 31, 23, 0, 0), "Work Shift", System.Drawing.Color.Red))
        TheEvents.Add(New DatumEvent(New Date(2008, 9, 1, 15, 0, 0), New Date(2008, 9, 1, 23, 0, 0), "Work Shift", System.Drawing.Color.Red))
        TheEvents.Add(New DatumEvent(New Date(2008, 9, 2, 15, 0, 0), New Date(2008, 9, 2, 23, 0, 0), "Work Shift", System.Drawing.Color.Red))
        DrawEvents(Me.PictureBox1, New Date(2008, 8, 23, 0, 0, 0), 1, 9)
        DrawEvents(Me.PictureBox2, New Date(2008, 8, 25, 0, 0, 0), 1, 1)

    End Sub

    Public Sub DrawEvents(ByRef a As PictureBox, ByVal s As DateTime, ByVal DayWidth As Double, ByRef DayHeight As Double)
        Dim l As New TimeSpan(DayHeight * DayWidth, 0, 0, 0)
        Dim bmp As New Bitmap(a.Width, a.Height)
        Dim HeightOfRow As Double = a.Height / DayHeight
        Dim pg As Graphics = Graphics.FromImage(bmp)
        pg.Clear(Color.White)
        Dim FirstDatum As New DatumEvent(s, s, "", System.Drawing.Color.Black)
        Dim VerticalOffset As Double = 0
        Dim EventsMatches As IEnumerable(Of DatumEvent)
        For i = 0 To DayHeight - 1



It even can handle complex searches like to one below.
Find all the events the that start or in progress between the start date & time and the finish date & time.
' Using LINQ find all Events Start and End DateTImes
EventsMatches = From item In TheEvents _
  Select item _
 Where ((item.StartTime >= s) Or (item.StartTime.Add(item.Delta_TimeSpan) >= s)) _
 And ((item.StartTime < s.AddDays(DayWidth)) Or (item.StartTime.Add(item.Delta_TimeSpan) < s.AddDays(DayWidth)))


All that in 1 Line of code.

            ' For Each Matching Evetn draw it
            For Each MatchingEvent As DatumEvent In EventsMatches
                DrawEvent(pg, FirstDatum, MatchingEvent, DayWidth, VerticalOffset, HeightOfRow, DayWidth * i)
            Next
            ' Update Vertical offset
            VerticalOffset += HeightOfRow
            ' Adjust Start date for next row
            s = s.AddDays(DayWidth)
        Next i
        ' Stick the created bitmap into it picture box
        a.Image = bmp
    End Sub



Finally the code that draws the event.
    Public Sub DrawEvent( _
        ByRef g As Graphics, _
        ByVal TheDatumEvent As DatumEvent, _
        ByRef ThisEvent As DatumEvent, _
        ByVal DaysWide As Double, _
        ByVal VertialOffset As Double, _
        ByVal HeightOfRow As Double, _
        ByVal DayWidthValue As Double _
)
        Dim JulianStartOffset As Double = (ThisEvent.StartTime_Julian - TheDatumEvent.StartTime_Julian)
        Dim JulianEventWidth As Double = JulianStartOffset + ThisEvent.Delta_Julian
        Dim EventRect As New RectangleF( _
            (JulianStartOffset - DayWidthValue) * (g.VisibleClipBounds.Width / DaysWide), _
            VertialOffset, _
            ThisEvent.Delta_Julian * (g.VisibleClipBounds.Width / DaysWide), _
            HeightOfRow)
        Using p As New Pen(ThisEvent.EventColor)
            ' Draw Rectangle
            g.FillRectangle(p.Brush, EventRect.X, EventRect.Y, EventRect.Width, EventRect.Height)
            ' Draw the border
            g.DrawRectangle(Pens.Black, EventRect.X, EventRect.Y, EventRect.Width, EventRect.Height)
        End Using

    End Sub
End Class




So Basics are
Dim Results As IEnumerable(Of <The Type or Class>)
Results = SELECT item WHERE <SQL STATEMENT>
Note item is very useful on Lists.

So now you too can be a LINQ using code-ninja :ph34r:

This post has been edited by AdamSpeight2008: 14 August 2012 - 10:21 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Using LINQ

#2 AdamSpeight2008   User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

Posted 11 September 2008 - 07:32 PM

Using LINQ to calculate the Average
Imagine we need calculate the average speed of a number of runs.
So you define a class object to store the details of each run.
Public Class MyRun
    Private mRunDate As Date
    Public Property RunDate() As Date
        Get
            Return mRunDate
        End Get
        Set(ByVal value As Date)
            mRunDate = value
        End Set
    End Property
    Private mRunDist As Double
    Public Property RunDist() As Double
        Get
            Return mRunDist
        End Get
        Set(ByVal value As Double)
            mRunDist = value
        End Set
    End Property
    Private mRunTime As Double
    Public Property RunTime() As Double
        Get
            Return mRunTime
        End Get
        Set(ByVal value As Double)
            mRunTime = value
        End Set
    End Property

    Protected Overrides Sub Finalize()
        MyBase.Finalize()
    End Sub

    Public Sub New(ByVal DateOfRun As Date, ByVal RunKms As Double, ByVal RunMins As Double)
        RunDate = DateOfRun
        RunDist = RunKms
        RunTime = RunMins
    End Sub
End Class



Add in a few runs, and calculate the average speed.
Public Class Form1
    Dim Runs As New List(Of MyRun)
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Distance(km) 5 4 5 5 5 5 29
        'Time (mins) 18.7 17.3 18.3 20 18.8 19.3 112.4
        Runs.Add(New MyRun(New Date(2008, 9, 1), 5, 18.7))
        Runs.Add(New MyRun(New Date(2008, 9, 2), 4, 17.3))
        Runs.Add(New MyRun(New Date(2008, 9, 3), 5, 18.3))
        Runs.Add(New MyRun(New Date(2008, 9, 4), 5, 20))
        Runs.Add(New MyRun(New Date(2008, 9, 5), 5, 18.8))
        Runs.Add(New MyRun(New Date(2008, 9, 6), 5, 19.3))
        Console.WriteLine(AverageKph)
     End Sub

    Private Function AverageKph() As Double
        Return (Aggregate item As MyRun In Runs Into Sum(item.RunDist)) / (Aggregate item As MyRun In Runs Into Sum(item.RunTime)) * 60
    End Function
End Class



How do the AverageKph Function work?
Basically it is perform the follow sum

SUM OF DISTANCES
----------------------- = KmPerMinute
SUM OF TIMES

since we want Kph, it need to be multiplied by 60.

Advance Average
Now we only calculate the average speed between to dates.
    Private Function AverageKphForDate(ByVal FromD As Date, ByVal ToD As Date) As Double
        If FromD.CompareTo(ToD) > 0 Then
            Throw New Exception("From Date can not be after ToDate")
        End If
        Dim RunBetweenDates As IEnumerable(Of MyRun)
        RunBetweenDates = From item As MyRun In Runs Select item Where (item.RunDate >= FromD And item.RunDate <= ToD)
        Dim avg As Double = (Aggregate item As MyRun In RunBetweenDates Into Sum(item.RunDist)) / (Aggregate item As MyRun In RunBetweenDates Into Sum(item.RunTime)) * 60
        If Double.IsNaN(avg) Then    Return 0
        Return avg
    End Function


Was This Post Helpful? 0
  • +
  • -

#3 AdamSpeight2008   User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

Posted 13 September 2008 - 09:04 PM

The following correction to the DatumEvent Class in the First Example, correctly computes a variation of Julian Date.
    Private Function JDate(ByVal ThisDate As DateTime) As Double
        Return ThisDate.Subtract(New Date(1, 1, 1, 0, 0, 0)).TotalDays
    End Function


Was This Post Helpful? 0
  • +
  • -

#4 AdamSpeight2008   User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

Posted 02 November 2008 - 04:05 AM

Calculate the Distribution Of Letters In A Sentence

  Dim TheSentence As String = "ABCDEFGHIJKLMNOPQRTSUVWXYZA"
  Dim Alphabet As String = "ABCDEFGHIJKLMNOPQRTSUVWXYZ"
Dim LetterCounts As IEnumerable(Of Integer) = From Letter In TheSentence, Alphabet_Letter In Alphabet.Distinct _
 Where Char.ToUpper(Letter) = Alphabet_Letter _
 Group Letter By Alphabet_Letter Into LetterGroups = Group Select LetterGroups.Count
For i As Integer = 0 To LetterCounts.Count - 1
Console.WriteLine("{0} => {1}", TheSentence(i), LetterCounts(i))
Next


Was This Post Helpful? 0
  • +
  • -

#5 AdamSpeight2008   User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

Posted 03 November 2008 - 11:59 PM

Counts of Words
    Private Sub CountWords()
        Dim TheSentence As String = "THE QUICK BROWN FOX LEAPED OVER THE LAZY BROWN DOG"
        Dim WordCounts As IEnumerable = From TheWords In TheSentence.Split(" ").ToList, DistinctWords In TheSentence.Split(" ").ToList.Distinct.ToList _
        Where TheWords.ToUpper = DistinctWords.ToUpper _
        Group TheWords By DistinctWords Into CountsOfLetters = Group Select Word = DistinctWords, Number = CountsOfLetters.Count

        For Each i In WordCounts
            Console.WriteLine("Word: {0} Count:{1}", i.Word.ToString, i.Number.ToString)
        Next
    End Sub



Edited: To Add Explanation

Take the sentence and split (at the spaces) it into a list of words TheWords
Do the same but this them removing duplicates DistinctWords
Find all the words in TheWords that have a match in DistinctWords group them by DistinctWords
Count the number of items in each group.

This post has been edited by AdamSpeight2008: 04 November 2008 - 12:55 AM

Was This Post Helpful? 0
  • +
  • -

#6 AdamSpeight2008   User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

Posted 17 November 2008 - 04:57 PM

Get the difference between two lists.
 Dim servers() As String = {"A", "B", "C", "D"}
 Dim localFiles() As String = {"D", "B"}
 Dim downloadfile As IEnumerable(Of String) = servers.Except(localFiles.AsEnumerable)
 ' downloadfile -> {"A","C"}



Edit: Update It also removes duplicates for the returned list.
Was This Post Helpful? 0
  • +
  • -

#7 AdamSpeight2008   User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

Posted 30 January 2009 - 10:18 AM

Concatenate the Results into single string.
 Dim test() As String = {"APPLE", "PEAR", "PEACH", "PLUM"}
 Sub Main()
  Dim a As String = (From T As String In test Select T Where T Like "P*").Aggregate(Function(current As String, nexta As String) current + ", " + nexta)
  Console.ReadKey()
 End Sub


Was This Post Helpful? 0
  • +
  • -

#8 AdamSpeight2008   User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

Posted 20 February 2009 - 02:40 PM

Just for a bit of fun.
99 Bottles of Beer in LINQ

Module Module1

 Sub Main()
  ' A LINQ Version of 99 Bottles of Beer
  ' Note: This is a single line of code.
  Console.WriteLine((From b In Enumerable.Range(0, 100).Reverse _
					 Select SS = String.Format( _
					 CStr(IIf(b = 0, _
							  "No More Bottles of Beer", _
							  CStr(IIf(b > 1, _
								   String.Format("{0} Bottles of Beer", b), _
								   String.Format("{0} Bottle of Beer", b)) _
								  ))) _
					 & " on the wall, " & _
					 CStr(IIf(b = 0, _
							  "No More Bottles of Beer", _
							  CStr(IIf(b > 1, _
								   String.Format("{0} Bottles of Beer", b), _
								   String.Format("{0} Bottle of Beer", b)) _
								  ))) _
					 & "." & vbNewLine & _
					 CStr(IIf((b - 1) >= 0, _
					 "Take one down and pass it around, " & _
					 CStr(IIf((b - 1) = 0, _
					  "No More Bottles of Beer", _
					  CStr(IIf((b - 1) > 1, _
					   String.Format("{0} Bottles of Beer", b - 1), _
					   String.Format("{0} Bottle of Beer", b - 1)) _
					  ))) _
					  & " on the wall.", "Go to the store and buy some more, 99 bottles of beer on the wall.")) _
					  & vbNewLine & vbNewLine)).Aggregate(Function(currentVerse As String, nextVerse As String) currentVerse + nextVerse))
  Console.ReadKey()
 End Sub

End Module


Was This Post Helpful? 0
  • +
  • -

#9 AdamSpeight2008   User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

Posted 25 June 2009 - 06:01 PM

Examples of how to do Hangman
Dim Guesses As New List(Of Char)
  Guesses.Add("A")
  Guesses.Add("E")
  Guesses.Add("N")
  Guesses.Add("D")
  Dim Space As Char = " "
  Dim UnknownLetter As Char = "-"
  Dim WordToGuess As String = "DREAM IN CODE"
  Dim Display_1 As String = (From l In WordToGuess Select CChar(If(l = " ", Space, If(Guesses.Contains(l), l, UnknownLetter)))).ToArray
  Dim Display_2 As String = WordToGuess.Aggregate(Of String)("", New Func(Of String, Char, String)(Function(a As String, l As Char) a & CChar(If(l = " ", Space, If(Guesses.Contains(l), l, UnknownLetter)))))
  Dim Display_3 As String = WordToGuess.Select(New Func(Of Char, Char)(Function(l) If(l = " ", Space, If(Guesses.Contains(l), l, UnknownLetter)))).ToArray


This post has been edited by AdamSpeight2008: 25 June 2009 - 06:01 PM

Was This Post Helpful? 0
  • +
  • -

#10 AdamSpeight2008   User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

Posted 04 October 2009 - 06:39 PM

A 2 Line Generic Quicksort
 
Public Module Extensions
 Dim CompareValues() As Integer = {-1, 0, 1}
 <Runtime.CompilerServices.Extension()> _
  Public Function QuickSort(Of T As IComparable(Of T))(ByVal input As IEnumerable(Of T)) As IEnumerable(Of T)
  Dim result = (From cv As Integer In CompareValues _
				Group Join iv As T In input _
				On iv.CompareTo(input(0)) Equals cv _
				Into Group _
				Select Group)
  Return If(input.Count < 2, _
			input, _
			QuickSort(result(0)) _
			.Concat(result(1)) _
			.Concat( _
			  QuickSort(result(2)) _
			 ) _
		   )
 End Function
End Module



Example
  Dim a As Integer() = {4, 3, 2, 1}
 ' If r was an IEnumerable the ToArray wouldn't be needed
  Dim r As Integer() = a.QuickSort().ToArray


Was This Post Helpful? 0
  • +
  • -

#11 bhogsett   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 03-January 10

Posted 03 January 2010 - 06:52 AM

I need help with the LINQ except method.

This code is working:

For Each g In Regex.Matches(searchtext, searchterm) _
.Cast(Of Match)() _
.GroupBy(Function(m) m.Value) _
.OrderBy(Function(m) m.Key)
aResult = " " & g.Key & ControlChars.Tab & ControlChars.Tab _
& ControlChars.Tab & g.Count & ControlChars.CrLf
string_Builder.Append(aResult)
Next

The program first reads a file and puts the contents into searchtext and creates the searchterm.

I want to be able to exclude common words (e.g., the, that, this, about, etc.) from the output.

Your example seemed to be the solution, so I added

.Except(excludelist.AsEnumerable) but that throws an error.

excludelist is defined as:

Dim excludelist() As String = {"the", "The", "about"}

Thanks.

Bill
Was This Post Helpful? 0
  • +
  • -

#12 AdamSpeight2008   User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

Posted 03 January 2010 - 09:18 PM

How can I help you without now the error message, the searchtext you used and the searchterm?
Was This Post Helpful? 0
  • +
  • -

#13 bhogsett   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 03-January 10

Posted 04 January 2010 - 06:46 AM

View PostAdamSpeight2008, on 3 Jan, 2010 - 08:18 PM, said:

How can I help you without now the error message, the searchtext you used and the searchterm?


Sorry, I thought I had given you enough. :rolleyes:

Here is the error message:

Unable to cast object of type 'System.String[]' to type 'System.Collections.Generic.IEnumerable`1[System.Text.RegularExpressions.Match]'.

Here is the code:

Dim excludelist() As String = {"the", "The", "about"}
		
'Order by number of times word used with Fewest Uses first
		If Not isDisplayOrderAlpha And Not IsDisplayOrderHighToLow Then
			For Each g In Regex.Matches(searchtext, searchterm) _
				.Cast(Of Match)() _
				.Except(excludelist.AsEnumerable) _
				.GroupBy(Function(m) m.Value) _
				.OrderBy(Function(m) m.Count).ThenBy(Function(m) m.Key)
				aResult = "  " & g.Key & ControlChars.Tab & ControlChars.Tab & ControlChars.Tab & g.Count & ControlChars.CrLf
				string_Builder.Append(aResult)
			Next
		End If


searchtext is a string created as follows:

Dim data As IDataObject = Clipboard.GetDataObject
		Dim searchtext As String = data.GetData(DataFormats.Text).ToString


The Clipboard has just been filled with data from a Word file or from a text file.

searchterm is a string created as follows:

Dim searchTerm As String
searchTerm = "[\w'\p{M}-]{3,}"


Thanks

Bill
Was This Post Helpful? 0
  • +
  • -

#14 AdamSpeight2008   User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

Posted 05 January 2010 - 06:09 AM

The error is very self explanatory.
Unable to cast object of type 'System.String[]' to type System.Collections.Generic.IEnumerable`1[System.Text.RegularExpressions.Match]'.

An IEnumerable(Of RegularExressions.Match) are not the same the same an array of strings.

So append the part of each match you want to the stringbuilder.
Was This Post Helpful? 0
  • +
  • -

#15 bhogsett   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 03-January 10

Posted 05 January 2010 - 11:26 AM

View PostAdamSpeight2008, on 5 Jan, 2010 - 05:09 AM, said:

The error is very self explanatory.
Unable to cast object of type 'System.String[]' to type System.Collections.Generic.IEnumerable`1[System.Text.RegularExpressions.Match]'.

An IEnumerable(Of RegularExressions.Match) are not the same the same an array of strings.

So append the part of each match you want to the stringbuilder.


Thanks. What I don't understand fills books.

Before your reply, I worked on the problem by doing the except before the regex match and had some success. But the results I got from Except were not what I expected. So I took your example and modified it slightly to show what I am seeing.

Here is your revised example:

Dim targetstring() As String = {"A", "B", "C", "D", "D", "A"}
		Dim excludestring() As String = {"D", "B"}

		Dim finalstring As IEnumerable(Of String) = targetstring.Except(excludestring.AsEnumerable)

		Dim theresult As String = ""
		For Each word In finalstring
			theresult = theresult & word & " "

		Next
		Debug.Print("Here are the finalstring contents:  " & theresult)



I expected to get A C A, but only get A C. :blink:

It looks like Except is removing items in the excludestring and duplicates of items in the targetstring.

Is this what you would expect? If so, is there a workaround?

Thanks.

Bill
Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2