Case-sensitive comparisons of strings function - Forum

Forum Navigation
You need to log in to create posts and topics.

Case-sensitive comparisons of strings function

@gaev has asked me to publish this script from him as the security system rejects it:

{NeoBook Function}
Version=5.80
Language=VBScript
Param=[%1]|Text|firstString
Param=[%2]|Text|secondString
Param=[%3]|Variable|result
{End}
intCompare = StrComp("[%1]","[%2]",0)
' MsgBox "[%1]" & " - " & "[%2]" & " - " & intCompare
If intCompare = -1 Then
   compareResult = "isLessThan"
End If
If intCompare = 0 Then
   compareResult = "isEqual"
End If
If intCompare = 1 Then
   compareResult = "isGreaterThan"
End If
' MsgBox compareResult

publication.nbSetVar "[%3]", compareResult

He will add some comments soon.
Thanks!

Uploaded files:
  • You need to login to have access to uploads.
Vadim has reacted to this post.
Vadim

@gaev

Thanks for the helpful input !!

Thanks @luishp for loading the file on the forum.

If you want to Call this Function in any of your Publications, just save it in the VisualNEOWin Functions folder.

After that, any time you need case-sensitive compares, do something like this ...

SetVar "[strA]" "abcd"
SetVar "[strB]" "ABCD"
Call "CaseSensitiveIf" "[strA]" "[StrB]" "[resultVariable]"
AlertBox "compareResult" "[strA][#13][resultVariable][#13][strB]"

[resultVariable] will contain one of ...

isLessThan
isEqual
isGreaterThan

Happy comparing !

Vadim has reacted to this post.
Vadim

Hi Gaev!

Thanks for your case-sensitive comparison script. I wonder why you use VBScript. Within VisualNeo Win the following code has the same result (or do I miss something?) Notice the use of the magical ! character that guarantees case-sensitive comparisons.

If "![str1]" "=" "![str2]"
AlertBox "Case-sensitive compare" "[str1] = [str2]"
Else
If "![str1]" ">" "![str2]"
AlertBox "Case-sensitive compare" "[str1] > [str2]"
Else
If "![str1]" "<" "![str2]"
AlertBox "Case-sensitive compare" "[str1] < [str2]"
EndIf
EndIf
EndIf

Best regards,
Reinier

Vadim and proforma.guyot have reacted to this post.
Vadimproforma.guyot

@reinier

You are right ... the ! before the variables does the trick.

I offered it as a workaround after it was assumed by many (including me) that the If command had a defect (feature ?) that only did non-case-sensitive compares.

Now that I think about it, I believe that Dave posted the same solution on the NeoBook forum ... looks like I am having more of those senior moments :-(

Thanks for the reminder.