Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q3018 How can I compare two strings for case-sensitivity?

irt.org | Knowledge Base | ColdFusion | Q3018 [ previous next ]

Q3018 How can I compare two strings for case-sensitivity?

String1 = "myString"
String2 = "MyString"

To compare these two strings without case-sensitivity, we would just say:

<cfif string1 eq string2>....</cfif>

This CFIF would return a TRUE value, and execute the code between the CFIF tags.

However, to make the comparison case-sensitive, we can use the ColdFusion Compare() function.

<cfif Compare(string1,string2) eq "0">...</cfif>

In this case, the two strings are not the same and will not execute the code between the CFIF tags.

The Compare() function performs a check on the ASCII values of the characters in each string. The function returns a negative number if string1 is less than string2, zero(0) if string1 is equal to string2, or a positive number if string1 is greater than string2.

Feedback on 'Q3018 How can I compare two strings for case-sensitivity?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.