Split string based on number of characters RRS feed

  • Question

  • Hi,

    I have a simple map where I receive a Streetname out of the source and have to write that streetname to the Address1 element in the destination. The issue is that the destination Address1 element can only contain 100 characters.

    If it has more then 100 characters then I have to split the string into the Address2 element.

    The next question is how I can do it the good way so that the string would be split between spaces and not in the middle of a word. For example:

    Streetname1 Streetname2 Streetname3 Streetname4 Streetname5 Streetname6 Streetname7 Streetname8 Streetname9

    The hundredth character is between t and r in Streetname9. So the cleanest solution would be to place everything in address1 and Streetname9 in address 2.

    How can I achieve this?

    Friday, March 13, 2015 12:40 PM


All replies

  • I would use Custom XSLT in a Map.

    Morten la Cour

    Friday, March 13, 2015 1:10 PM
  • You could create the method as a function in a helper library and call the same in the mapper. Refer to https://msdn.microsoft.com/en-us/library/aa560879.aspx?f=255&MSPPError=-2147217396 on how to create a custom functoid.

    In the custom functoid you could use a System.String.Split function on " " to get a string array. You can then use a string builder to return address line 1 and 2, etc.


    • Marked as answer by Angie Xu Wednesday, March 25, 2015 7:43 AM
    Friday, March 13, 2015 1:38 PM
  • Hold on!

    Before you start asking about technical details, you need to get from the business exactly how they want to handle this situation.

    Address Line 2, in the US at least, it not a wrap field, it's a separate Address element. 100 characters is very generous so right or wrong, most times, it's just truncated.

    If they really to space split at <100 chars, you can use .LastindexOf.  For example:

            public int PositionOfLastSpaceBeforeLimit(string input, int limit)
                return input.LastIndexOf(' ', limit);

    Then wire the output to two Substring Functoids.

    Friday, March 13, 2015 3:13 PM
  • I had faced a similar situation in which output element could only contain 100 characters after that i had to split rest of characters in batch of 100 characters and repeated the element.

    This was achieved by implementing recursion through XSLT. For this I created a template which will return a substring a generate an element with that element. This template will take two parameters-1) Complete string 2) Length (100 in your case).

    check the below article for a sample


    Please mark this post accordingly if it answers your query or is helpful.

    Friday, March 13, 2015 8:03 PM