Search
Web Braintrove
Site Navigation
Home
Products
Tags
Levels
Dates
Authors
5 MOST RECENT
Locate Conditional Formatting and Custom Validation in InfoPath 2010
Conditionally Display Different Values In a Single Expression Box
Create a Button With a Blank Label
Create Shared Rules
Force a Field Value to a Boolean Using Rules
5 MOST POPULAR
Access a Method in a Master Page with Code-Behind
Pass Query String Parameters to an ASP.NET Xml Control
Prevent Namespace Prefixes from Being Copied to the Output
Create Groups in a Drop-Down List Box
Configure IIS 7 for Custom Error Pages
5 MOST FORGOTTEN
Create a Rusted Text Effect Using Styles
Convert Between Time and Decimal
Install Windows 7 Beta onto a Virtual Machine
Create a Drop Cap Using CSS
Enable Themes in Windows Server
Microsoft MVP
This article has been viewed 162 times.

Perform a Case-Insensitive String Comparison without Using Translate()

Page 1 of 2
Written by Gregory Scot Collins
Thursday, 20 August 2009, 6:48 PM
This article has been tested to work with the following products and versions. No guarantee of compatibility, with or without modification, is offered for products or versions other than those listed.
  • InfoPath 2010, 2007 and 2003 (Microsoft)
  • Office 2010, 2007 and 2003 (Microsoft)
InfoPath experts, including myself, have long advised that to perform a case-insensitive string comparison you needed to use the translate() function to convert both strings to uppercase or lowercase. The comparison would look something like:
translate(my:String1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz") = translate(my:String2, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz")

Complexity

While this works fine in most cases, it is long to type and is prone to errors (both of which can be mitigated by having a template tucked away somewhere that you can copy and paste). Complexity only increases with the need of additional functions before the strings can be compared, such as substring(), string-before(), or string-after(), etc.

International characters

Another potential bug farm occurs when there is the possibility that international characters will be present. Any such characters would need to be explicitly added to the translate() statement.

Alternate function

Microsoft provides developers with a set of extended functions including one named msxsl:compare-string(). The msxsl namespace is actually part of the function name and must be present.
InfoPath defaults to it using this function when you add conditional formatting that compares two dates. The resulting comparison is something like:
msxsl:string-compare(my:Date1, my:Date2) > 0
Advanced InfoPath developers have long known about this function, but its true power remains undocumented. I recently discovered it while pondering whether there was another version of this function that included the ability to do a case-insensitive comparison.
In my searching, I found a comparable function named ms:string-compare() which includes two optional parameters: one for a language and one for comparison options that makes it possible to perform case-insensitive comparisons. A quick test revealed that msxsl:string-compare() also supports these two undocumented optional parameters; and it even works back in InfoPath 2003!
Bookmark this Article
StumbleUpon  Stumble It!
Digg  Digg It!
del.icio.us  del.icio.us
Article Tags
Great Deals
TigerDirect Exclusive Deals, Limited Time Offers, Act Now And Save!
Find all current special offers on Adobe products.
Try SugarSync Free!
Join WebHost4Life.com
TigerDirect
Computers4SURE (4SURE.com - An Office Depot Co.)
Copyright © 2006-2010 Braintrove. All rights reserved. Braintrove, braintrove.com, and the Braintrove logo are trademarks of Gregory Scot Collins in the United States and/or other countries. The names of actual companies and products mentioned herein may be the trademarks of their respective owners. Any rights not expressly granted herein are reserved.