on 02-07-2007 7:20 PM
Hi Experts ,
I have a requirement in which I have to pad an incoming string with spaces based on it's length so that it's size ultimately become 10 character...can anyone give me a udf code for the same.I have tried myself but it didn't work
Hi Deepak,
Try this
1. calculate the length of the string(str) = len
2.
while (len <= 10)
{
a) append a space to the string
b) len = str.len
}
Regards,
Akshay
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi ,
Got the following when I tried this code
usr/sap/JXS/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Maped3f5b80b6e511dba9a0001125a6778d/source/com/sap/xi/tf/_MM_Inbound_Delv_.java:888: cannot resolve symbol symbol : variable result location: class com.sap.xi.tf._MM_Inbound_Delv_ result.addValue(str); ^
Hi Deepak,
for sure it is an infinite loop, you have to recompute the value of the variable len inside the loop or do in this way:
while (str.length() <= 10)
str = str + " ";
result.addValue(str);
//return str; *** depending on the type of function
without the need to declare a variable for string lenght.
Regards,
Sergio
Deepak,
Just create a UDF and click on <b>Value</b> radio button. In the arguments name the Argument as <b>str</b>.
Then inside you put as given by sergio:
while (str.length() <= 10)
str = str + " ";
return str;
--> Save and close.
Then it will work.
---Satish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Deepak,
This function will resolve your issue:
For e.g. if a string has to be padded with leading zeros to make it 10 character long.
while (String.length()<Integer.parseInt(Length))
{
String = Value+String;
}
return String;
---Satish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.