Jump to content



Photo

Case Sensitive String Compare


  • Please log in to reply
2 replies to this topic

#1 Matt @ MPCS

Matt @ MPCS

    Just another AutoIt user trying to help out! :)

  • Active Members
  • PipPipPipPipPipPip
  • 700 posts

Posted 22 September 2004 - 11:25 PM

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

Plain Text         
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







#2 Valik

Valik

    Former developer.

  • Active Members
  • PipPipPipPipPipPip
  • 18,879 posts

Posted 22 September 2004 - 11:29 PM

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

#3 Matt @ MPCS

Matt @ MPCS

    Just another AutoIt user trying to help out! :)

  • Active Members
  • PipPipPipPipPipPip
  • 700 posts

Posted 22 September 2004 - 11:33 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users