Class FieldComparison
Word's comparison semantics for conditional fields (ECMA-376 Part 1 §17.16.5.19).
public static class FieldComparison
- Inheritance
-
FieldComparison
- Inherited Members
Remarks
Every rule below is measured against Word 16.0.20228 by
tools/Probe-WordIfOperands.ps1 (90 probes, results at
tools/word-if-operands.measured.json) and recorded as WQ-0007. Phase 14
shipped this class with four rules inferred rather than measured, and all four were wrong;
the probe exists because SKIPIF and NEXTIF share this code and decide which
records a mail merge emits, so an error here changes the record set while the output still
looks structurally perfect.
- The left operand decides. A quoted left operand forces a textual
comparison even when it looks numeric —
"5.0" = 5is false. Otherwise the comparison is numeric when both operands parse as numbers, and the right operand's quoting is irrelevant:5.0 = "5"is true. - Text comparison is case-sensitive, and orders character by
character on a fused weight: letters sort above every non-letter, ordered by base letter,
with lowercase immediately before uppercase. So
"a" < "A" < "b", and"Abc" < "abd"is false — the comparison stops at the first character and never reaches thec/d, which a multi-level collation would have used. See CompareText(string, string). - Wildcards do not depend on quoting.
=and<>switch to wildcard matching whenever the right operand contains*or?, quoted or not. Matching is case-sensitive, patterns are honored on the right operand only, and ordering operators never wildcard. - Parenthesized negatives are not numeric.
(5)is the text"(5)", which is why(5) < (4)is false. This matches the independent finding for table cells recorded as WQ-0006.
Methods
- CompareText(string, string)
Compares two operands using Word's field text ordering.
- Evaluate(string, FieldComparisonOperator, string, bool, bool, CultureInfo)
Evaluates a comparison.
- Evaluate(string, FieldComparisonOperator, string, bool, CultureInfo)
Evaluates a comparison whose left operand was not written quoted.
- ParseOperator(string?)
Parses a comparison operator.
- TryParseNumber(string?, CultureInfo, out double)
Parses a field operand as a number, by Word's rule.
- WildcardMatch(string, string)
Matches text against a Word field wildcard pattern, where
*matches any run of characters and?matches exactly one.