Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8009999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:36:28+00:00 2026-06-04T18:36:28+00:00

I have a case insensitive dictionary in asp.net/vb.net like this: Dim caseInsensitiveDictionary = New

  • 0

I have a case insensitive dictionary in asp.net/vb.net like this:

Dim caseInsensitiveDictionary = New Dictionary(Of String, Single)(StringComparer.OrdinalIgnoreCase)

it holds values like this

one hundred, 100
one hundred one, 101
one hundred two, 102

I want that if a user tries to find a value like this:

Response.Write(dictionary("ONE-hundred").ToString)

he gets 100 but right now it gets exception because dictionary keys don’t have hyphon ‘-‘. Which method do i need to override.

please suggest

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T18:36:29+00:00Added an answer on June 4, 2026 at 6:36 pm

    You could either add ONE-hundred,100 as well to the dictionary(the easiest approach) or build a custom StringComparer:

    Class CaseInsensitiveIgnoringStringComparer
        Inherits StringComparer
        Private caseInsentiveComparer As System.StringComparer = StringComparer.OrdinalIgnoreCase
        Public Property IgnoreList As IList(Of String) = Nothing
        Public Property ReplaceWith As String = " "
    
        Private Function Replace(original As String) As String
            If IgnoreList Is Nothing OrElse IgnoreList.Count = 0 Then
                Return original
            Else
                For Each s As String In IgnoreList
                    original = original.Replace(s, ReplaceWith)
                Next
                Return original
            End If
        End Function
    
        Public Overloads Overrides Function Compare(x As String, y As String) As Integer
            Return caseInsentiveComparer.Compare(Replace(x), Replace(y))
        End Function
    
        Public Overloads Overrides Function Equals(x As String, y As String) As Boolean
            Return caseInsentiveComparer.Equals(Replace(x), Replace(y))
        End Function
    
        Public Overloads Overrides Function GetHashCode(obj As String) As Integer
            Return caseInsentiveComparer.GetHashCode(Replace(obj))
        End Function
    End Class
    

    testing

    Dim comp = New CaseInsensitiveIgnoringStringComparer() With {.IgnoreList = {"-", "+"}, .ReplaceWith = " "}
    Dim caseInsensitiveDictionary = New Dictionary(Of String, Single)(comp)
    caseInsensitiveDictionary.Add("One hundred", 100)
    caseInsensitiveDictionary.Add("One hundred one", 101)
    caseInsensitiveDictionary.Add("One hundred two", 102)
    
    ' normally following both lines would cause exceptions '
    Dim n100 = caseInsensitiveDictionary("ONE-hundred")
    n100 = caseInsensitiveDictionary("oNE+Hundred")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like my dictionary to be case insensitive. I have this example code: text
I have a large dictionary constructed like so: programs['New York'] = 'some values...' programs['Port
How do you have a case insensitive insertion Or search of a string in
I have a varbinary field id like to do a case-insensitive search on. I
I have found this answer useful: Accent and case insensitive COLLATE equivalent in Oracle
If not, I think lower(string) could be used to have a case insensitive comparison,
I have a case sensitive SERVER (SQL_Latin1_General_CP1_CS_AS) but the Database is Case insensitive (SQL_Latin1_General_CP1_CI_AS).
I have to compare two strings for case insensitive equality which one is faster
I have a list of names that I want to match case insensitive, is
I have this case <WrapPanel> <CheckBox>Really long name</CheckBox> <CheckBox>Short</CheckBox> <CheckBox>Longer again</CheckBox> <CheckBox>Foo</CheckBox> <Slider MinWidth=200

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.