on 06-04-2008 1:14 PM
Hi All,
I have a small requirement where i want to find the underscore and then put additional zeros to it.
ex:
0041234567_123456789123
Now i just want to find the underscore( "_") and calculate the number of characters from left and if it is less than 13 i should added zeros to it.
i.e. find the number of characters before underscore("_")
= 10 characters(0041234567)
pick those 10 characters(0041234567)
add zeros to it from left (0000041234567)
return the result as 0000041234567_123456789123
I have written the function to add zeros to it, i just want the code to find the underscore and add zeros from left.
code:
int n;
int v;
String str ;
for ( int i =0 ;i<a.length; i++)
{
str = "0";
v = a<i>.length();
n =13 -a<i>.length();
for ( int k = 0;k< (n-1); k ++)
str = str +"0";
if ( v ==13)
result.addValue(a<i>);
else
{
a<i> = str+a<i>;
result.addValue(a<i>);
}
}
Thanks a lot in advance.
JGD.
Use the Java indexOf method.
String a = "asd";
int i = a.indexOf("s");
Here i = 1.
I think you should change your line:
str = str +"0";
to be
str = "0" +str;
since you want zeros in front.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thanks buddy,,
point will be assigned...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Great....
The only problem is it is returning only the first part and not the whole string padded with zeros.
returning : 0000041234567
and not ; 0000041234567_123456789123
thanks in advance..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Change the function to:
int ind, l1;
String first, last;
for (int i = 0; i<a.length; i++) {
ind = a<i>.indexOf("_");
first = a<i>.substring(0,ind);
last = a<i>.substring(ind+1, a<i>.length());
l1 = first.length();
for (int j = l1; l1<13; l1++) {
first = "0" + first;
}
result.addValue(first + "_" + last);
}
Regards,
Yaghya
thanks buddy for your quick responce.
i am getting some error:
/usr/sap/XD1/DVEBMGS03/j2ee/cluster/server0/./temp/classpath_resolver/Mape57d5f70323411ddb7ef0003bae4e429/source/com/sap/xi/tf/_MM_ABC_SR3_01_.java:1637: package result does not exist result.addValue first; ^ /usr/sap/XD1/DVEBMGS03/j2ee/cluster/server0/./temp/classpath_resolver/Mape57d5f70323411ddb7ef0003bae4e429/source/com/sap/xi/tf/_MM_ABC_SR3_01_.java:1637: first is already defined in testing$(java.lang.String[],com.sap.aii.mappingtool.tf3.rt.ResultList,com.sap.aii.mappingtool.tf3.rt.Container) result.addValue first; ^ 2 errors
thanks in advance.
JGD
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try the following code:
int ind, l1;
String first, last;
for (int i = 0; i<a.length; i++) {
ind = a<i>.indexOf("_");
first = a<i>.substring(0,ind);
//last = a<i>.substring(ind+1, a<i>.length());
l1 = first.length();
for (int j = l1; l1<13; l1++) {
first = "0" + first;
}
result.addValue(first);
}
It will return the first part and pas it with zeros at the beginning.
Regards,
Yaghya
Edited by: Yaghya Nana on Jun 4, 2008 2:54 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
76 | |
9 | |
8 | |
7 | |
6 | |
5 | |
5 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.