KAPOW

Would you like to react to this message? Create an account in a few clicks or log in to continue.
KAPOW

Welcome to the Kapow forum. Here you can get help, use your skills to help others and enjoy hanging out in the company of other Kapow Robot Developers.


2 posters

    [solved]Padding fields in Kapow?

    avatar
    JKL


    Posts : 5
    Points : 1920
    Join date : 2019-02-05

    [solved]Padding fields in Kapow? Empty [solved]Padding fields in Kapow?

    Post by JKL Sun Apr 07, 2019 11:39 pm

    I am building an output file that has to be formatted to have the fields in a specific set of columns.  For example, the field for the company ID is designated as Text(80) to be placed in position 3-82 of the file row, but the actual company ID is only 20 characters.  I need to pad the end of the name with spaces, so, for example:
    "MyCompany"
    becomes
    "MyCompany                                           " (with the correct number of spaces)
    There are also numeric fields that need to be specific lengths, so a number of 123 has to be formatted to 000123.
    I couldn't find such a function in Kapow.  There are trim and collapse functions, but no padding that I see.
    Does anyone have a good solution for this?
    Thanks much.
    jking
    jking


    Posts : 103
    Points : 3852
    Join date : 2014-03-01
    Location : USA

    [solved]Padding fields in Kapow? Empty Re: [solved]Padding fields in Kapow?

    Post by jking Tue Apr 09, 2019 8:06 pm

    Here is one possible solution.
    After you have extracted the CompanyName (or assigned CompanyName) add an Assign/Transform Variable - Convert Variable.
    In Conversions, add an Evaluate Expression Step.  Expression is variable+"                                                                                                                                                                                                                                                    " (add a number of spaces greater than the field length required).
    Add a Text Formatting → Replace Pattern step.  Pattern is (.{??}).* where ?? is the field length you need.  In your example below, pattern would be (.{80}).*
    In the screen shot below, I added a step to test the length of mycompany to show the results.


    [solved]Padding fields in Kapow? Pad_le11
    avatar
    JKL


    Posts : 5
    Points : 1920
    Join date : 2019-02-05

    [solved]Padding fields in Kapow? Empty Thank you! Another solution...

    Post by JKL Wed Apr 10, 2019 4:02 am

    Thanks so much!  Your solution is much more elegant than mine.  I finally came up with this:
    PayerID + substring("                                                                                ",length(PayerID),80)

    where there are 80 spaces in the first parameter of the substring function, which is the total length of the string.

    Sponsored content


    [solved]Padding fields in Kapow? Empty Re: [solved]Padding fields in Kapow?

    Post by Sponsored content


      Current date/time is Mon Apr 29, 2024 6:32 am