Sign in to follow this  
Followers 0
Matt @ MPCS

Case Sensitive String Compare

3 posts in this topic

I know all of the more advanced coders out there can write this on their own, but for those of you looking to compare strings taking into consideration letter case here is a little UDF to help.

AutoIt: v3.0.103.0

Written by Matt

Name: CompString()

Parameters: String1, String2

Return: 1 if they are equal, -1 of not equal

Func CompString( $String1, $String2 )
   
   Local $i
   Local $StrVal1, $StrVal2
   
   $StrVal1 = 0
   $StrVal2 = 0
   
   If( $String1 = $String2 ) Then
      
      For $i = 1 to StringLen( $String1 )
         $StrVal1 = $StrVal1 + Asc( StringMid( $String1, $i, 1 ) )
      Next

      For $i = 1 to StringLen( $String2 )
         $StrVal2 = $StrVal2 + Asc( StringMid( $String2, $i, 1 ) )
      Next

      If( $StrVal1 = $StrVal2 ) Then
         Return 1
      EndIf
   EndIf
   
   Return -1

EndFunc

I haven't seen anything else like this on the forum or in the documentation so I figured I would post it since it has worked really well for me.

Always interested in questions, comments, bug reports. Thanks for your time.

*** Matt @ MPCS

Share this post


Link to post
Share on other sites



Uhhh... open the help file, open the "Language Reference" 'folder' and choose "Operators". Then read the description for operator==.

Share this post


Link to post
Share on other sites

Thanks Valik... I was sure I missed it somewhere. It is already posted so if one of the admins wants to remove it that is fine. Most of the work I do isn't case sensitive so I hadnt run across that yet. Thanks for pointing that out though.

*** Matt @ MPCS

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