Second method is tested and works.
How to reproduce a if-then-condition for infopath fields.
concat(
substring(TrueResult, 1, (BoolCondition) * string-length(TrueResult)),
substring(ElseResult, 1, (not(BoolCondition)) * string-length(ElseResult)))
The easy way meaning not too much code involved.
Klassen und Objekte im InfoPath Namespace.
Bis Version 2003, danach gilt der "Interop"-Namespace!
Klassen und Objekte im InfoPath Namespace