none
Case [IN]Sensitive RRS feed

  • Question

  • It just occurred to me.  Visual Basic is case insensitive!

    OK, I am a little slow and while I have always known this, I didn't think about it until I was thinking about passwords.

    Now I know of several ways to compare a string for case, but it just seems to me that there should simply be a property that does that.  So is there a property for that?


    gwboolean

    Tuesday, July 2, 2019 4:15 PM

Answers

  • So, basically, there is no property setting for a textbox control that can be used for Case sensitivity.

    I am disappointed.


    gwboolean

    Give me the exact syntax you want, write it out e.g.

    Dim Result As Boolean = TextBox1.CompareExact(TextBox2)

    Where CompareExact would return true if TextBox1.Text = "Karen" and TextBox2.Text = "Karen" but in one or the other is "karen" return false.

    Here is how the above would look via a custom TextBox

    Public Class Form1
        Private Sub CompareButton_Click(sender As Object, e As EventArgs) Handles CompareButton.Click
            If TextBoxCaseSensitive1.CompareExact(TextBoxCaseSensitive2) Then
                MessageBox.Show("Exact match")
            Else
                MessageBox.Show("Not exact match")
            End If
        End Sub
    End Class
    Public Class TextBoxCaseSensitive
        Inherits TextBox
        ''' <summary>
        ''' Compare exact text of this and another TextBox
        ''' </summary>
        ''' <param name="pOtherTextBox"></param>
        ''' <returns></returns>
        Public Function CompareExact(pOtherTextBox As TextBox) As Boolean
            Return String.Equals(Text, pOtherTextBox.Text)
        End Function
    End Class
    


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange


    Tuesday, July 2, 2019 7:57 PM
    Moderator

All replies

  • Hi

    If you compare two strings - lets say "abcdef" and "Abcdef", you will find they do not match - therefor, Case Sensitive.


    Regards Les, Livingston, Scotland



    • Edited by leshay Tuesday, July 2, 2019 4:26 PM
    Tuesday, July 2, 2019 4:26 PM
  • True that.

    However, what I would like to know is if there is a property that will do that, or can be made to do that?

    I know of several ways to use code to do this, but it just seems to me that there should be a property for that.


    gwboolean

    Tuesday, July 2, 2019 4:46 PM
  • True that.

    However, what I would like to know is if there is a property that will do that, or can be made to do that?

    I know of several ways to use code to do this, but it just seems to me that there should be a property for that.


    gwboolean

    Hi

    Please give an example of what you want. A string either matches or doesn't. I commonly use either .ToUpper or .ToLower on strings to match case InSensitive.


    Regards Les, Livingston, Scotland

    Tuesday, July 2, 2019 5:06 PM
  • What I want is a control property setting, if one exists for that.

    If I cannot set a control property or the property setting does not exist, then I already know how to code to compare Upper/Lower case characters in a string.

    What I would be looking for would look something like this:

    txtTextBox.SettingProperty.Setting = Something


    gwboolean

    Tuesday, July 2, 2019 6:50 PM
  • What I want is a control property setting, if one exists for that.

    If I cannot set a control property or the property setting does not exist, then I already know how to code to compare Upper/Lower case characters in a string.

    What I would be looking for would look something like this:

    txtTextBox.SettingProperty.Setting = Something


    gwboolean

    Hi

    I am still unclear of your needs. What would the Property you want actually do to the TextBox in real terms - do you mean the Property would cause user entry into such a TextBox to be changed in some way (say) to Proper Case or something else?


    Regards Les, Livingston, Scotland

    Tuesday, July 2, 2019 7:03 PM
  • Perhaps the following will satisfy you. Add the following code sample to your project.

    Public Module Extensions
        <Runtime.CompilerServices.Extension>
        Public Function AreEqual(pSelf As String, pValue As String) As Boolean
            Return String.Equals(pSelf, pValue)
        End Function
        <Runtime.CompilerServices.Extension>
        Public Function IsEqualNoCase(pSelf As String, pValue As String) As Boolean
            Return String.Equals(pSelf, pValue, StringComparison.OrdinalIgnoreCase)
        End Function
    End Module

    Usage mix with conventional methods

    Dim value1 = "Karen"
    
    Console.WriteLine(String.Equals(value1, "Karen"))
    Console.WriteLine(value1.AreEqual("karen"))
    Console.WriteLine(value1.AreEqual("Karen"))
    Console.WriteLine(value1 = "Karen")
    Console.WriteLine(value1.IsEqualNoCase("karen"))


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, July 2, 2019 7:39 PM
    Moderator
  • So, basically, there is no property setting for a textbox control that can be used for Case sensitivity.

    I am disappointed.


    gwboolean

    Tuesday, July 2, 2019 7:53 PM
  • So, basically, there is no property setting for a textbox control that can be used for Case sensitivity.

    I am disappointed.


    gwboolean

    Give me the exact syntax you want, write it out e.g.

    Dim Result As Boolean = TextBox1.CompareExact(TextBox2)

    Where CompareExact would return true if TextBox1.Text = "Karen" and TextBox2.Text = "Karen" but in one or the other is "karen" return false.

    Here is how the above would look via a custom TextBox

    Public Class Form1
        Private Sub CompareButton_Click(sender As Object, e As EventArgs) Handles CompareButton.Click
            If TextBoxCaseSensitive1.CompareExact(TextBoxCaseSensitive2) Then
                MessageBox.Show("Exact match")
            Else
                MessageBox.Show("Not exact match")
            End If
        End Sub
    End Class
    Public Class TextBoxCaseSensitive
        Inherits TextBox
        ''' <summary>
        ''' Compare exact text of this and another TextBox
        ''' </summary>
        ''' <param name="pOtherTextBox"></param>
        ''' <returns></returns>
        Public Function CompareExact(pOtherTextBox As TextBox) As Boolean
            Return String.Equals(Text, pOtherTextBox.Text)
        End Function
    End Class
    


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange


    Tuesday, July 2, 2019 7:57 PM
    Moderator
  • So, basically, there is no property setting for a textbox control that can be used for Case sensitivity.

    I am disappointed.


    gwboolean

    Hi

    Your question makes no sense to me. A TextBox is usually used for Input - all input being String characters - as per the User choice - Upper/Lower case, whatever thery want. You can then interact with the input string in thousands of ways to verify/format/validate etc

    You still haven't explained what such a Property would be, how it would be used and what it would effect. The closest I can imagine, as I said above, would be to alter the User input in a TextBox as they type to (say) Proper Case (capitalizing the first char of each word  (say).


    Regards Les, Livingston, Scotland

    Tuesday, July 2, 2019 8:46 PM
  • Thanks Karen.  

    This is for a password. 

    I did not even think about that until one day (about a week ago), I remembered that VB was case insensitive and it occurred to me that my password method was case insensitive, which is was.

    This is why I am disappointed that I could find no property or tool for this.  However, you saved me from the dreaded you tube videos (they are actually quite good for information, but it is truly lousy to have to sit through one).


    gwboolean

    Wednesday, July 3, 2019 5:25 PM
  • Thanks Karen.  

    This is for a password. 

    I did not even think about that until one day (about a week ago), I remembered that VB was case insensitive and it occurred to me that my password method was case insensitive, which is was.

    This is why I am disappointed that I could find no property or tool for this.  However, you saved me from the dreaded you tube videos (they are actually quite good for information, but it is truly lousy to have to sit through one).


    gwboolean

    Glad to help but also check out a demo I did which does what you want using data annotations. Not saying to change what you have but consider what I've done in the demo.

    https://1drv.ms/u/s!AtGAgKKpqdWjjTUyUAqFM1ycDpEA?e=KnsJy3

    All the imports are in the .zip

    Imports ValidatorLibrary.Classes
    Imports ValidatorLibrary.LanguageExtensions
    Imports ValidatorLibrary.Validators
    
    Public Class LoginForm
        Private retryCount As Integer = 0
        Private Sub LoginButton_Click(sender As Object, e As EventArgs) _
            Handles LoginButton.Click
    
            Dim login As New CustomerLogin With
                    {
                        .Name = UserNameTextBox.Text,
                        .Password = PasswordTextBox.Text,
                        .PasswordConfirmation = PasswordConfirmTextBox.Text
                    }
    
            Dim validationResult As EntityValidationResult =
                    ValidationHelper.ValidateEntity(login)
    
            If validationResult.HasError Then
                If retryCount >= 3 Then
                    MessageBox.Show("Guards toss them out!")
                    Close()
                End If
                MessageBox.Show(validationResult.ErrorMessageList())
                retryCount += 1
            Else
                Dim f As New MainForm(login.Name)
                f.Show()
                Hide()
            End If
        End Sub
    End Class
    


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, July 3, 2019 6:13 PM
    Moderator