Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old July 30th, 2007, 12:09 AM
werD's Avatar
werD werD is offline
Certified Abuser
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jan 2005
Location: Line 73 ---^
Posts: 1,046 werD User rank is First Lieutenant (10000 - 20000 Reputation Level)werD User rank is First Lieutenant (10000 - 20000 Reputation Level)werD User rank is First Lieutenant (10000 - 20000 Reputation Level)werD User rank is First Lieutenant (10000 - 20000 Reputation Level)werD User rank is First Lieutenant (10000 - 20000 Reputation Level)werD User rank is First Lieutenant (10000 - 20000 Reputation Level)werD User rank is First Lieutenant (10000 - 20000 Reputation Level)werD User rank is First Lieutenant (10000 - 20000 Reputation Level)  Folding Points: 20652 Folding Title: Starter FolderFolding Points: 20652 Folding Title: Starter Folder
Time spent in forums: 1 Week 4 Days 20 h 37 m 12 sec
Reputation Power: 127
Custom Predicate

Just wanted to add to this post a simple custom predicate class i wrote, to test this out. this will search a list of type string for a specific value. It uses an enum for different types of searches which can be expanded or whatever. mine needs to be a little more intense than this requiring some additional parameters for where to search, but i just wanted to test the concept and store it somewhere before I went to bed and forgot about it.

Code:
Public Class CustomPredicate
    Public Enum searches As Integer
        Contains = 1
        IsEqualTo = 2
        DoesntContain = 3
    End Enum
    Public FilterKey As String
    Public Pred As Predicate(Of String)
    Public Sub New(ByVal type As searches,Optional ByVal Key as String = Nothing)
      If Not(Key Is Nothing)  Then
         FilterKey = Key
      End If
        Select Case type
            Case searches.Contains
                Pred = AddressOf Contains
            Case searches.DoesntContain
                Pred = AddressOf DoesntContain
            Case searches.IsEqualTo
                Pred = AddressOf IsEqualTo
        End Select
    End Sub
    Public Function Contains(ByVal s As String) As Boolean
        Return InStr(s.ToLower, FilterKey.ToLower, CompareMethod.Binary) > 0
    End Function
    Public Function DoesntContain(ByVal s As String) As Boolean
        Return Not (InStr(s.ToLower, FilterKey.ToLower, CompareMethod.Binary) > 0)
    End Function
    Public Function IsEqualTo(ByVal s As String) As Boolean
        If s.ToLower = FilterKey.ToLower Then
            Return True
        Else
            Return False
        End If
    End Function
End Class


Here's how to use it.
Code:
Dim l as New List(Of String)
        l.Add("1")
        l.Add("2")
        l.Add("3")
        l.Add("deez")
        l.Add("doze")
Dim myPredicate As New CustomPredicate(CustomPredicate.searches.Contains)  

        myPredicate.FilterKey = "e"

Dim str() as String = l.FindAll(myPredicate.Pred)

'str(0) = "deez"    str(1) = "doze"


'another example

Dim str2() as String = l.FindAll(New CustomPredicate(CustomPredicate.searches.DoesntCon  tain, "e").Pred)

'str(0) = "1"   str(1) = "2"   str(2) = "3"
Comments on this post
Shadow Wizard agrees!
TimLensen agrees: Very nice addition indeed, thanks for sharing.
__________________
werD, MCSD .Net
<% ASP,.NET App Development %>

Really Help People with Real Diseases... And Get a Cool Blue Flower!

If a post has helped you please use the scales... we all need bigger heads

Last edited by werD : July 30th, 2007 at 10:14 AM.

Reply With Quote
  #2  
Old July 30th, 2007, 01:50 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,942 Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 340699 Folding Title: Super Ultimate Folder - Level 1Folding Points: 340699 Folding Title: Super Ultimate Folder - Level 1Folding Points: 340699 Folding Title: Super Ultimate Folder - Level 1Folding Points: 340699 Folding Title: Super Ultimate Folder - Level 1Folding Points: 340699 Folding Title: Super Ultimate Folder - Level 1Folding Points: 340699 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 5 Days 12 h 47 m 26 sec
Reputation Power: 1537
this deserve place of honor in the Code Bank - thanks for sharing!

Reply With Quote
  #3  
Old July 30th, 2007, 01:52 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,942 Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 340699 Folding Title: Super Ultimate Folder - Level 1Folding Points: 340699 Folding Title: Super Ultimate Folder - Level 1Folding Points: 340699 Folding Title: Super Ultimate Folder - Level 1Folding Points: 340699 Folding Title: Super Ultimate Folder - Level 1Folding Points: 340699 Folding Title: Super Ultimate Folder - Level 1Folding Points: 340699 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 5 Days 12 h 47 m 26 sec
Reputation Power: 1537
Quote:
Originally Posted by werD
Just wanted to add to this post a simple custom predicate class i wrote, to test this out
very nice buddy, in case you didn't see I have made this new
thread and moved to the Code Bank Forum. thanks!

Reply With Quote
  #4  
Old July 30th, 2007, 10:12 AM
werD's Avatar
werD werD is offline
Certified Abuser
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jan 2005
Location: Line 73 ---^
Posts: 1,046 werD User rank is First Lieutenant (10000 - 20000 Reputation Level)werD User rank is First Lieutenant (10000 - 20000 Reputation Level)werD User rank is First Lieutenant (10000 - 20000 Reputation Level)werD User rank is First Lieutenant (10000 - 20000 Reputation Level)werD User rank is First Lieutenant (10000 - 20000 Reputation Level)werD User rank is First Lieutenant (10000 - 20000 Reputation Level)werD User rank is First Lieutenant (10000 - 20000 Reputation Level)werD User rank is First Lieutenant (10000 - 20000 Reputation Level)  Folding Points: 20652 Folding Title: Starter FolderFolding Points: 20652 Folding Title: Starter Folder
Time spent in forums: 1 Week 4 Days 20 h 37 m 12 sec
Reputation Power: 127
Cheers To That Shadow! I was looking for that post to add the ability to initialize the filterkey to make it a one line call, and was like, "Did my post disappear?". It's nice to know it will be easily available./

Thanks hope it helps someone else as well

Reply With Quote
  #5  
Old July 30th, 2007, 10:17 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,942 Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 340699 Folding Title: Super Ultimate Folder - Level 1Folding Points: 340699 Folding Title: Super Ultimate Folder - Level 1Folding Points: 340699 Folding Title: Super Ultimate Folder - Level 1Folding Points: 340699 Folding Title: Super Ultimate Folder - Level 1Folding Points: 340699 Folding Title: Super Ultimate Folder - Level 1Folding Points: 340699 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 5 Days 12 h 47 m 26 sec
Reputation Power: 1537
lol post #3 should have come in the original thread, my bad..
glad you found this thread and thanks again!

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > Custom Predicate


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway