Tuesday, July 19, 2011

How to remove leading zeros from the value of element in a map

Charan: I have one additional requirement to my old problem mentioned here. Now I want to remove the leading  Zeros for the value of Element1 in addition to finding the existence of this optional element in input schema. Is there any easy way to do it.

Rohit: hmmm yes we can do it using the scripting functoid and simple C# code. Let me show you how.

Step1: Add new scripting functoid.

Step2: Configure Functoid Script use Inline C# as Script Type: and use the following simple C# code to remove the leading zeros in string:

public string RemoveLeadingZeros(string param1)
      string result=param1;
          result=param1.TrimStart(new char[]{'0'});        
      return result;

Step3: Modify the existing scripting functoid to use this code to remove the leading zeros:

<Element xmlns:p="http://CheckNodeExistenceInMap.InputSchema_XML">
        <xsl:when test="/p:Record/Element1">
            <xsl:value-of select="userCSharp:RemoveLeadingZeros(string(/p:Record/Element1))" />
            <xsl:value-of select="/p:Record/Element2" />

Rohit Sharma


suresh said...

Its Nice...I was not aware we can call the C# function .... For removing leading Zeros you can use TrimStart('0') function ...

Rohit Sharma said...

Thanks Suresh for pointing this out I have incorporated your comment.

Post a Comment