cancel
Showing results for 
Search instead for 
Did you mean: 

UDF to Append after particular length

Former Member
0 Kudos

Hi All,

I have a requirement where in i need to check the input string length for greater than 132 and when found so it needs to be appended for every 132 characters. Please let me know the UDF to acheive the same.

Thanks in advance,

Sai

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Sai,

Need little more explanation from your side....

i need to check the input string length for greater than 132 and when found so it needs to be appended for every 132 characters

If input string length >132 char then append ?

If input string length <132 char. then ?

In general , PI mapping requirements are like

If particular field length is 10 and we are getting 5 fields then we append the remaining 5 places with spaces.

this is done basically when the output file is of fixed length and we need to preserve the lengths.

Please share your requirement or solution if already you got the way to implement.

Regards,

Srinivas

former_member181962
Active Contributor
0 Kudos

Hi ,

Try this,


 int textLen = input[0].length();
String sub;
if (textLen > 132) 
{
int si = 0;
int ei = 132;
while (si < textLen) 
{
if (ei > textLen) ei = textLen;
sub=input[0].substring(si,ei);
result.addValue(sub);
si = ei;
ei = ei+132;
}
}
else 
{
result.addValue(input[0]);
}

This UDF must be a Queue type with one input parameter with name "input"

Regards,

Ravi

Former Member
0 Kudos

Hi,

Try with this UDF,


public String appenString(String input,Container container)
{

String output = input;
for(int i=input.length();i<132;i++)
{

output = output + " "; // i considered u want to postfix  with space... if anything else change accordingly the 2nd parameter.

}

return output;


}

Former Member
0 Kudos

Hi

Few changes with reference to above code.... use the below code.



String Output = Input;
String Spaces = "";

for(int i=input.length();i<132;i++)
{
 
Spaces = Spaces + " ";   
}

Output  = Input + Spaces ;

return output;

Regards

Ramg

Former Member
0 Kudos

Hi

if str length is greater 132 what needs to be appended? i think your requirement will be if string length is less than 132 then need to append with spaces till 132.

correct me if my understanding is not correct.

Regards

Ramg