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

    Function Name
    Retrieve right-most section of a String to a particular length
    String Text String to retrieve right part of
    Length Length of result String
    Result Text String comprising the right-most characters from the input String, with number of characters specified by Length input
    none -


    The Data Mapper String Right function retrieves the right-most section of an input String, with the length also specified as input. In other words, the Right function retrieves the last n characters in the input String, creating a substring containing these characters. The Right function is useful if your target data model involves size restrictions, allowing you to limit the length of particular mapped String items. To apply the String Right 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 product_source.xsd, an XML Schema Definition inferred from the following source:

    Source XML
    Copy Code
      <name>Kitchen Chair</name>
      <description>This lovely chair has lots of fantastic qualities ag65d4hn78</description>
      <name>Table Lamp</name>
      <description>This beautiful lamp is a very special item h76gfr45v2</description>

    For our target schema we will be using product_target.xsd, inferred from the following XML:

    Target XML
    Copy Code
     <item category="Electrical">
     <item category="Gardening">

    The data models produce for a retail service. For demonstration, let's assume that the "description" item in the input contains a code as its final 10 characters - this code is all we want to map to the output Schema, perhaps to use it as a reference within this or another data source. Here is the Data Mapper with Source and Target imported:

    Data Mapper String Right Function

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

    String Right Component

    String Right Transform Added

    The String Right function takes two inputs and gives a single output. The String input should be connected to the source text String item to retrieve the result text from. The Length input requires a number input indicating the length of the desired right String section. The Right function output should be connected to the target item in the XML Writer or another component. First connect the "description" item in the XML Reader to the String input of the Right function:

    Reader to Right String Input

    Next connect the Right output to the "item_overview" item in the XML Writer:

    Right Output to Writer Input

    Now we need to specify the length of the desired right String portion. To do this, we need a Constant Value. Drag one from the Data Type section in the Component Palette onto the mapping area:

    Constant Value Added

    We need to specify the value we want the Constant to have. To do so, right-click it and choose Show Properties. Select one of the integer types from the drop-down Data Type menu and enter your chosen number in the Value field.

    Constant Properties

    For this example we are limiting the output String to the last 10 characters of the input String. Connect the Constant output to the Right function Length input:

    Constant to Right Input

    Now when the source item is mapped to the target item the values will be restricted to the 10 right-most characters.

    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
     <item category="Furniture">
      <item_name>Kitchen Chair</item_name>
     <item category="Lighting">
      <item_name>Table Lamp</item_name>

    The input element value has been limited to the last 10 characters as part of the mapping process. Often, XML mapping involves converting from legacy systems to new applications in which you may have restrictions in terms of storage space. The Right function can therefore be useful for both human-readable and non-human-readable Strings comprising data items in which you do not need all characters to be preserved when mapping to a new model.

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

    See Also