Skip to main content
aamirs4807
April 30, 2025
Question

Handling Special Characters in Rich Text Items in Appian

  • April 30, 2025
  • 9 replies
  • 1 view

When working with rich text components in Appian, I encountered issues with displaying special characters correctly, particularly backslashes (\) and other escape characters like tabs (\t) and newlines (\n). These characters can be misinterpreted or escaped incorrectly, leading to incorrect rendering in the interface.

Example Scenario

Consider the following example, where you have a string containing file paths with backslashes that you want to display in an a!richTextItem component:

"File Path:\nC:\Users\tUserXyz\Documents\Project\file.txt\tAnotherPath:\nC:\Users\nUserXyz\Documents\Report\report.txt"

Actual Output: "File Path: C:\Users UserXyz\Documents\Project\file.txt AnotherPath: C:\Users UserXyz\Documentseporteport.txt"
Expected Output: "File Path: C:\Users\tUserXyz\Documents\Project\file.txt AnotherPath: C:\Users\nUserXyz\Documentseporteport.txt"

Root Cause

The issue arises because backslashes and other escape characters are special characters used for escaping other characters. When not properly escaped, they can be misinterpreted, leading to incorrect rendering. For example:

  • \n is interpreted as a newline.
  • \t is interpreted as a tab.
  • \ is used for escaping other characters.

Attempted Solution

To correctly display these special characters in rich text components, I attempted to use the substitute function to replace each escape character with its intended representation.

Here’s the approach I took:

  1. Escape Special Characters in the Source String: Used the substitute function to replace each escape character with its intended representation.

  2. Use the Correct Substitution Pattern: Ensure that the substitution pattern correctly handles \n, \t, and \.

Implementation

Here’s an example implementation demonstrating how I tried to handle special characters, particularly backslashes, tabs, and newlines, in an a!richTextItem component:

a!localVariables(
  local!formattedText: substitute(
      substitute(
        substitute(
          substitute(
            ri!inputText,
            "\n", char(10)
          ),
          "\t", char(9)
        ),
        "\\", char(92)
      ),
      "\r", ""
    ),
local!formattedText
)

Request for Solution

Despite implementing the above approach, I still face issues with displaying special characters in file paths fetched from an API. If anyone has encountered similar issues or has suggestions for handling these escape characters more effectively, please share your insights or solutions.

9 replies

harshas2775
April 30, 2025

I attempted the scenario as is and its working for me. \n, \t all are visible appropriately in the rich text display field. May be just check if the variable you are passing in the richtextitem() is having file path as intented or not. 

aamirs4807
April 30, 2025

I have updated the string

harshas2775
May 2, 2025

Few questions:

1. In the Actual/Expected output above - looks like you want to subjectively handle \n, \t etc.

    The expected output shows \t and \n in the string 

    File Path: C:\Users\tUserXyz\Documents\Project\file.txt

    Another File Path: C:\Users\nUserXyz\Documentseporteport.txt

   So my understanding is these are expected in the directory path but not before and after. 

   Do you want to remove just the highlighted ones from ri!inputText? 

   "File Path:\nC:\Users\tUserXyz\Documents\Project\file.txt\tAnotherPath:\nC:\Users\nUserXyz\Documents\Report\report.txt"

2. You mentioned API sends the file path. Can you elaborate on any operation you are doing on the API response to achieve this         inputText or API is returning the file path entirely in this format 

"File Path:\nC:\Users\tUserXyz\Documents\Project\file.txt\tAnotherPath:\nC:\Users\nUserXyz\Documents\Report\report.txt"

stefanhelzle0001
April 30, 2025

There is a "more simple" approach to substituting multiple items in a string.

a!localVariables(
  local!text: "File Path:\nC:\Users\tUserXyz\Documents\Project\file.txt\tAnotherPath:\nC:\Users\NUserXyz\Documents\Report\report.txt",
  reduce(
    substitute(_,_,_),
    local!text,
    merge(
      {"\n", "\N", "\t", "\T", "\\", "\r", "\R"},
      {char(10), char(10), char(9), char(9), char(92), "", ""}
    )
  )
)

This uses the two arrays inside merge() to substitute the first item in the first array with the first item in the second array and so forth. I suggest to read the documentation on the functions reduce() and merge(), and also read the section around partial evaluation

docs.appian.com/.../expression-advanced-evaluation.html

aamirs4807
April 30, 2025



I am still getting the issue.

Actual Output: "File Path: C:\Users UserXyz\Documents\Project\file.txt AnotherPath: C:\Users UserXyz\Documentseporteport.txt"
Expected Output: "File Path: C:\Users\tUserXyz\Documents\Project\file.txt AnotherPath: C:\Users\nUserXyz\Documentseporteport.txt"

stefanhelzle0001
April 30, 2025

Switch to "Raw" in the test output.