Results 1 to 19 of 19

Thread: case sensative

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    13

    case sensative

    i'm currently writing a search program code on vb.net, is there anyway i can make it so that my searchwords are NOT case sensative?

    ex: searchword "error" would return results such as "ERROR" "ErRor" "error" "eRRoR" etc.

    anyhelp would be greatly appreciated

  2. #2
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    I would change the case of the string you are searching to match the case of the string you are searching with.

    VB Code:
    1. Dim sError As String = "This is an ErrOr"
    2. Dim sSearch As String = "Error"
    3. If sError.ToLower().IndexOf(sSearch.ToLower()) > -1 Then
    4.     MessageBox.Show("Found it!")
    5. End If
    Whadayamean it doesn't work....
    It works fine on my machine!

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    13
    well its a little more complicated than that... see i need to essentially enter random text documents looking for these words so changing the words in the documents i'm searching through probably won't be possible, is there any other alternative? BTW thanks for the suggestion.

  4. #4
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    it isn't necessary to change the text of the documents. In order to read the documents, you would have to open them into a streamreader anyway, just assign the contents to a variable and then compare the string in the variable with your search value.

    If you find it do what you need to do with the rest of the contents of the document.
    Whadayamean it doesn't work....
    It works fine on my machine!

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    13
    hey... thats not a bad idea... sorry cyberhawk, i misunderstood you the first time. Thanks!

  6. #6
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    Well, use RegularExpressions as they are dead more fast
    \m/\m/

  7. #7
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    Absolutely, I was going to send a follow-up message once I got home, but you beat me to it.
    Whadayamean it doesn't work....
    It works fine on my machine!

  8. #8
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by PT Exorcist
    Well, use RegularExpressions as they are dead more fast
    Hi,

    He is a new guy and you want him to use REGEX????? That's like putting a 14 year old into an Indy.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  9. #9
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    Yeah, but if he makes that first lap...
    Whadayamean it doesn't work....
    It works fine on my machine!

  10. #10
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Well, if you decide not to go with RegEX, use the the Compare method of the String class.

    VB Code:
    1. If String.Compare("hi", "Hi", True) = 0 Then Messagebox.Show("Equal")

  11. #11
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    actually, that was where we started before we started talking about REGEX.
    Whadayamean it doesn't work....
    It works fine on my machine!

  12. #12
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Originally posted by taxes
    That's like putting a 14 year old into an Indy.
    We already have 14 year olds in the Indies. Same goddamn rednecks winning every time.

  13. #13
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by mendhak
    We already have 14 year olds in the Indies. Same goddamn rednecks winning every time.
    I thought the last Indy Redneck to win was Nigel Mansell.

    One up for the UK (BUt only one I'm afraid )
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  14. #14
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    Originally posted by mendhak
    We already have 14 year olds in the Indies. Same goddamn rednecks winning every time.
    geez, i hate rednecks!!! lol=))

  15. #15
    Lively Member TLord's Avatar
    Join Date
    Jun 2004
    Posts
    95
    Why all of this ?

    VB.Net offers a compilation option: Option Compare, this option controls the behavior of the program when comparing string values, there are 2 options: Option Compare Binary which forces the strings to be in the same case for true equationing, Option Compare Text which compares the text by their characters ignorign the case - and that is the optino you want.

    To use option include the statement in the top of the file preceeding any declaration (before the "Imports" statement also).

    Examples:
    VB Code:
    1. Option Compare Binary
    2. ...
    3. Dim Rs As Boolean
    4. If "AaBbCc" = "aabbcc" Then
    5. Rs = True 'Rs is still False
    6. End If

    VB Code:
    1. Option Compare Text
    2. ...
    3. Dim Rs As Boolean
    4. If "AaBbCc" = "aabbcc" Then
    5. Rs = True 'Rs is True now
    6. End If
    Do you think my life is easy?
    Do you think it's good to win?
    do you think it's nice to kill?
    Do you think learning is a must?
    Do you think computers are nothing?
    Do you think this post is stupid?
    Do ypu think we're really humen?

    DO YOU THINK IT'S GOOD TO THINK AT ALL? ? ? ! ! !

  16. #16
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    Originally posted by TLord
    Why all of this ?

    VB.Net offers a compilation option: Option Compare, this option controls the behavior of the program when comparing string values, there are 2 options: Option Compare Binary which forces the strings to be in the same case for true equationing, Option Compare Text which compares the text by their characters ignorign the case - and that is the optino you want.

    To use option include the statement in the top of the file preceeding any declaration (before the "Imports" statement also).

    Examples:
    VB Code:
    1. Option Compare Binary
    2. ...
    3. Dim Rs As Boolean
    4. If "AaBbCc" = "aabbcc" Then
    5. Rs = True 'Rs is still False
    6. End If

    VB Code:
    1. Option Compare Text
    2. ...
    3. Dim Rs As Boolean
    4. If "AaBbCc" = "aabbcc" Then
    5. Rs = True 'Rs is True now
    6. End If
    Option Compare has to do with how your source code compatibility is maintained, not how strings are compared.

    If what you are saying were true, then why would Microsoft invest the effort they have into REGEX.

    This kind of advice should be thoroughly researched before being offered.
    Whadayamean it doesn't work....
    It works fine on my machine!

  17. #17
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    Oops, my bad, I had something else on my mind, TLord is correct, I didn't pay close enough attention to what I was reading.

    My appoligies TLord
    Whadayamean it doesn't work....
    It works fine on my machine!

  18. #18
    Lively Member TLord's Avatar
    Join Date
    Jun 2004
    Posts
    95
    Originally posted by CyberHawke
    My appoligies TLord
    No need to apologise It's always nice to help
    Do you think my life is easy?
    Do you think it's good to win?
    do you think it's nice to kill?
    Do you think learning is a must?
    Do you think computers are nothing?
    Do you think this post is stupid?
    Do ypu think we're really humen?

    DO YOU THINK IT'S GOOD TO THINK AT ALL? ? ? ! ! !

  19. #19
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by CyberHawke
    Oops, my bad, I had something else on my mind, TLord is correct, I didn't pay close enough attention to what I was reading.

    My appoligies TLord
    Yes, you must not try to put too much into such a tiny space
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width