Skip to Content
0

Adding spaces for the output field

Jun 24, 2017 at 05:02 PM

78

avatar image

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Raghuraman S Jun 26, 2017 at 08:29 AM
0

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;

Share
10 |10000 characters needed characters left characters exceeded
Iñaki Vila Jun 26, 2017 at 09:23 AM
0

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.

Share
10 |10000 characters needed characters left characters exceeded
Harish Mistri Jun 26, 2017 at 03:09 AM
0

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

Share
10 |10000 characters needed characters left characters exceeded
Evgeniy Kolmakov Jun 26, 2017 at 12:02 PM
0

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.

Share
10 |10000 characters needed characters left characters exceeded