InfoPath - removing newline (CRLF) using rules

  1. In InfoPath (and in Windows in general), a newline is two characters \r\n (carriage return, followed by a newline character).

  2. You can’t easily use \r or \n within InfoPath rules, since the XML is escaped into \\r and \\n defeating your intention.

  3. First, add a characters secondary data source: Add an external XML file for characters
    You should get this secondary data source with the special characters we need.

  4. On the field that you want to remove newlines, add a changed rule:

    The translate rule is:
    translate(., @crlf, "")
    or expanded xpath:
    translate(., xdXDocument:GetDOM(“characters”)/lookups/characters/@crlf, "")

    use select field and change the datasource to characters.

  5. To prevent this rule from running into infinite loop, set a condition:

    The expression is:
    contains(., xdXDocument:GetDOM(“characters”)/lookups/characters/@crlf)

  6. Result:
     

Test it!


Test typing something with newline


Rule runs and removes any new line characters

Discussions