Skip to Content

Adding spaces for the output field

Hi All,

If the sender field value coming as blank, i want to add '406' spaces in the output field value. could you please suggest how can i achieve this requirement?

Regards,

Janardhan

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Jun 26, 2017 at 08:29 AM

    Check if the below UDF Helps

    if(var1.equals(""))
    {
    for(int i=0;i<406;i++)
    {
    var1 += new String(" ");
    }
    }
    else
    {
    var1 += new String("");
    }
    return var1;

    Add comment
    10|10000 characters needed characters exceeded

  • Jun 26, 2017 at 09:23 AM

    Hi,

    Also you can create a constant with 406 blanks and concatenate this constant if the source node length is zero. But definitely the best way is to do an UDF as Raghu and Harish mentioned, in this way you can do it more dynamic.

    Regards.

    Add comment
    10|10000 characters needed characters exceeded

  • Jun 26, 2017 at 03:09 AM

    Hi,

    I would create a udf to enter the space. The best way is create generic UDF with one space, length and alignment (right align or left align) as input. It can add the space to all the required fields.

    regards,

    Harish

    Add comment
    10|10000 characters needed characters exceeded

  • Jun 26, 2017 at 12:02 PM

    Hi, Janardhan!

    My five cents:

    public static String padString(String srcString, int strLength, String padChar) {
    return ((new String(new char[strLength]).replace("\0", padChar)) + srcString).substring(srcString.length());
    }

    It's generic code snippet to add required number of any symbol to the left (left padding).

    In your case it's enough to use this:

    return new String(new char[strLength]).replace("\0", padChar);

    Regards, Evgeniy.

    Add comment
    10|10000 characters needed characters exceeded