NamingUtilsCompareNames Method

Compares two object name strings using Revit's comparison rules.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)
Syntax
public static int CompareNames(
	string nameA,
	string nameB
)

Parameters

nameA  String
The first object name to compare.
nameB  String
The second object name to compare.

Return Value

Int32
An integer indicating the result of the lexical comparison between the two names. Less than zero if nameA comes before nameB in the ordering, zero if nameA and nameB are equivalent, and greater than zero if nameA is comes after nameB in the ordering.
Exceptions
ExceptionCondition
ArgumentNullException A non-optional argument was null
Remarks

This routine is similar to System.String.Compare(), but uses Revit rules for comparison. This involves breaking the names into alphabetic and numeric tokens and comparing tokens individually. Neither comparand is allowed to be .

Note that this routine does consider case in comparing names. Some Revit element types disallow assignment of names where the only difference with existing names is the case of one or more characters, while other element types do not have this restriction. This routine does not take the particular element type into account, so it may not identify all "duplicates" if the names are to be used for some element types. Attempting to set the name on the target Element should provide the final indication of whether it is valid.

See Also