Sign in to follow this  
Followers 0
nf67

Making string checks case-sensitive

7 posts in this topic

See topic title

Any way to do this?

Example:

$Choice = MsgBox(4,"Upper / Lower", "Press YES for upper case :: NO for lower case")
If $Choice = 6 Then
 $Letter = "A"
Else
 $Letter = "a"
EndIf

If $letter = "a" then ;Unfortunately, this is true, regardless of your choice.
 MsgBox(0,"You picked " & $Letter ,"The condition ( $Letter = ""a"" ) is met!")
EndIf

:(

Share this post


Link to post
Share on other sites



See topic title

Any way to do this?

Example:

$Choice = MsgBox(4,"Upper / Lower", "Press YES for upper case :: NO for lower case")
If $Choice = 6 Then
 $Letter = "A"
Else
 $Letter = "a"
EndIf

If $letter = "a" then ;Unfortunately, this is true, regardless of your choice.
 MsgBox(0,"You picked " & $Letter ,"The condition ( $Letter = ""a"" ) is met!")
EndIf

:(

Switch the operand in your comparison from "=" to "=="

Share this post


Link to post
Share on other sites

Thanks, but how do I go about this using the following (a switch statement)?

Switch $Letter
 Case "a"
 MsgBox(0,"lower case", "a")
 
 Case "A"
 MsgBox(0,"upper case", "A")
EndSwitch

:(

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

There are likley other methods to go about it, but the first that came to mind is:

Switch Asc($Letter)
 Case Asc("a")
 MsgBox(0,"lower case", "a")

 Case Asc("A")
 MsgBox(0,"upper case", "A")
EndSwitch

Switch Asc($Letter)
 Case 97
 MsgBox(0,"lower case", "a")

 Case 65
 MsgBox(0,"upper case", "A")
EndSwitch

The second switch, using the actual ascii character values (rather than converting them for each compare) would result in a lot less CPU usage.

Edit: The ASCII table is in the appendix of the helpfile.

Edit2: Another way to skin your cat (I'm sure there are more...):

If StringIsLower($Letter) Then
    Switch $Letter
        Case "a"
          MsgBox(0,"lower case", "a")
        Case "b"
    EndSwitch
Else
    Switch $Letter
        Case "A"
          MsgBox(0,"UPPER case", "A")
        Case "B"
    EndSwitch
EndIf

Edit3: Or... (although you might want a StringIsAlpha() test in there first):

If Asc($Letter) > 90 Then
    MsgBox(0,"lower case", $Letter)
Else
    MsgBox(0,"UPPER case", $Letter)
EndIf
Edited by Spiff59

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks, used StringIsLower($Letter) , however this is a thing I had actually expected to have an Opt() for :(

Edit: Has this topic unleashed your inner letter checker, Spiff59 :)?

Edited by nf67

Share this post


Link to post
Share on other sites

See topic title

Any way to do this?

Example:

$Choice = MsgBox(4,"Upper / Lower", "Press YES for upper case :: NO for lower case")
If $Choice = 6 Then
 $Letter = "A"
Else
 $Letter = "a"
EndIf

If $letter = "a" then ;Unfortunately, this is true, regardless of your choice.
 MsgBox(0,"You picked " & $Letter ,"The condition ( $Letter = ""a"" ) is met!")
EndIf

:(

Hi, your script works perfectly as is!!! I'm guessing you think its not working becase the "text" in the MsgBox(flag, title, text) displays the little a regardless if YES or NO button is pressed.

Simply make the "text" section use the $Letter variable like you did in the "title" section of the MsgBox(). For example it should read:

MsgBox(0,'You picked ' & $Letter, 'The condition ( $Letter = "' & $Letter & '" ) is met!')

Note the use of single quotes makes it easier to read especially when wanting to include double quotes as part of the string.

Hope this helps!

Share this post


Link to post
Share on other sites

Sorry Ssubirias, but that's not what I mean.

The example I provided isn't case-sensitive; despite the fact that the script checks for "a", it also runs the code when "A" is found.

Thanks anyway :(

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0