Liquid Studio Documentation
Data Mapping / Data Mapper Functions / By Category / String / TrimEnd
In This Topic
    TrimEnd
    In This Topic

    Function Name
    Trim End
    Category
    String
    Icon
    Trim Start
    Description
    Trim trailing whitespace from the end of an input String
    Inputs
    String Text String to trim trailing whitespace from
    Outputs
    Result Text String trimmed with whitespace characters removed from the end
    Properties
    none -

    Usage

    The Data Mapper String Trim End function returns an input String with any whitespace characters removed from the end. Since much XML data comes from unpredictable sources such as user input with a system, it is often necessary to trim whitespace characters during mapping, ensuring that the mapped data is ready for use and does not waste any unnecessary storage space. To apply the String Trim End transform function, use the following process:

    Create a new Data Mapper file, dragging your XML data source and targets into the editor area. For this example we are using review_source.xsd, an XML Schema Definition inferred from the following source:

    Source XML
    Copy Code
    <product_reviews>
     <review>
      <product_id>123</product_id>
      <content>
    
       I thought this was a really excellent product. 
    
      </content>
     </review>
     <review>
      <product_id>234</product_id>
      <content>
    
       I really hate this product.
    
      </content>
     </review>
    </product_reviews>
    

    We are intentionally including additional whitespace characters around the content for demonstration. For our target schema we will be using review_target.xsd, inferred from the following XML:

    Target XML
    Copy Code
    <user_reviews>
     <review_item product="456">
      This is a wonderful item.
     </review_item>
     <review_item product="567">
      This item has good points and bad points.
     </review_item>
    </user_reviews>
    

    The data models feedback reviews for products. Here is the Data Mapper with Source and Target imported:

    Data Mapper String Trim End Function

    Let's drag the String Trim End function from the Component Palette into the mapping area:

    String Trim End Component

    String Trim End Transform Added

    The String Trim End function takes one input and gives one output. The String input should be connected to the source text String item to trim trailing whitespace characters from. The String Trim End function output should be connected to the target item in the XML Writer or another component. First connect the "content" item in the XML Reader to the String input of the Trim End function:

    Reader to Trim End String Input

    Next connect the Trim End output to the Element Value item in the XML Reader:

    Trim End Output to Writer Input

    Notice that we are mapping an element in the source XML to an element value in the target XML. The Mapper maps freely between elements, attributes and values.

    Finally let's make the remaining input and output connections:

    Input and Output Connections Mapped

    We can now execute the transform by pressing Shift-F5 or the Execute button (Execute). The transform is applied and the file we selected as output opens in the editor:

    Output XML
    Copy Code
    <user_reviews>
        <review_item product="123">
     
       I thought this was a really excellent product.</review_item>
        <review_item product="234">
     
       I really hate this product.</review_item>
    </user_reviews>
    

    The input element value has been mapped without the trailing whitespace we had on the right in the XML source within the element content. Notice that the whitespace from the start of the input String has been preserved, with whitespace only removed from the right hand side. If you need whitespace trimmed from the left, use the Trim Start function or the Trim function if you need it trimmed from both ends.

    When text Strings come from varied sources such as text files and other data stores, it is common to end up with whitespace characters such as new lines, carriage returns and spaces being appended at one or both ends. For this reason the Trim functions can save considerable time spent carrying out manual alterations. Trimming your Strings means that your mapped text is immediately ready for user display and other uses.

    This is a scalar function so the standard rules apply if multiple values are presented to one or more inputs.

    See Also