|
-
Feb 28th, 2009, 03:06 AM
#17
Re: Select issue
Here it is, using LINQ:
vb.net Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim emailGroup As String
'set the max email addresses per batch, and email seperator character
Dim maxLengthPerBatch As Integer = 4
Dim emailSeperator As String = ";"
counter(True, maxLengthPerBatch)
Dim emailBatches = From email In emailGroup.Split(emailSeperator.ToCharArray) _
Group email By url = email.Split("@"c)(1) Into email = Distinct() _
Select splitted = From em In email _
Group em By gnum = (counter() Mod email.Count) \ maxLengthPerBatch Into em = Group _
Order By gnum, em _
Select emails = Join(em.ToArray, emailSeperator)
emailBatches = emailBatches.ToList
'now we have all the batches in our emailBatches variable
'so we can enumerate thru them and send emails
'let's see if it prints correctly in our debug window.
For Each batch In emailBatches
For Each item As String In batch
Debug.WriteLine(item)
Next
Next
End Sub
'dummy procedure to mimic i++ kind of thing in C#, since vb.net doesn't have one
Private Function counter(Optional ByVal reset As Boolean = False, Optional ByVal resetSeed As Integer = -1) As Integer
Static i As Integer = resetSeed
If reset Then i = resetSeed
i += 1
Return i
End Function
Pradeep
Last edited by si_the_geek; Mar 1st, 2009 at 03:21 PM.
Reason: removed accidental Email tags
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|