on 08-01-2011 9:11 PM
Hi ,
I have to find a function where first I need to find the length of the source field and then split the contents into two different target fields based on the lenght .
For eg : sourcefield = 40 characters
I need to first check the length = 40 and then split into two fields target1 & target2 20 characters each.
If the source field is 30 characters then i need to split into 15 characters each.
I know there is a substring function to split but I do not know how to dynamically split by first getting the length.
Thanks,
Teresa
if u r one PI7.1 then chk this:
execution type: all values of a context.
Input will be var1 and add 2 resultlist result1 and result2...
int a = var1[0].length();
String a1 =var1[0].substring(0,a/2);
String b1 = var1[0].substring(a/2);
result1.addValue(a1);
result2.addValue(b1);
Ur mapping will be:
----------output1
Input--UDF----
------------output2
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
PLease use my reply. That code is for two different function.
public String splitFirstValue(String input, Container container) throws StreamTransformationException{
int length = input.length();
int splitLength = length/2;
String split1 = input.substring(0, splitLength);
return split1;
}
public String splitSecondValue(String input, Container container) throws StreamTransformationException{
int length = input.length();
int splitLength = length/2;
String split2 = input.substring(splitLength);
return split2;
}
You dont need any import statements.
But Bhaskar Don't we need a Input argument and output result . I cannot use the function without an input and output to map the source and target fields.
I did create a function with no input and output just as you said but not able to use it . I am creating a user definited function
Thanks,
Teresa
>I did create a function with no input and output just as you said but not able to use it . I am creating a user definited function
Looks like you dont understand what I mentioned.
Just copy What I did below
public String splitFirstValue(String var1, Container container) throws StreamTransformationException{
int length = var1.length();
int splitLength = length/2;
String split1 = var1.substring(0, splitLength);
return split1;
}
public String splitSecondValue(String var1, Container container) throws StreamTransformationException{
int length = var1.length();
int splitLength = length/2;
String split2 = var1.substring(splitLength);
return split2;
}
source field -->splitFirstValue --> target first element
source field >splitSecondValue>target second element
Edited by: Baskar Gopal on Aug 2, 2011 12:35 PM
Hi ,
Try this code.
String inval;
if(String.length==40)
{
String Tar1,Tar2;
Tar1=Substring(0,19);
Tar2=Substring(20,40);
res1=resultlist.addContextChange(Tar1);
addValue(res1);
res2=resultlist.addContextChange(Tar2);
addValue(res2);
Srini
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There are many ways to do this.... YOu can try UDF as below.. create a function and pass input as string.
Function 1) For the first split to target
int length = input.length();
int splitLength = length/2;
String split1 = input.substring(0, splitLength);
return split1
Function 2 ) For the second split to target
int length = input.length();
int splitLength = length/2;
String split2 = input.substring(splitLength);
return split2
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
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.