on 10-04-2008 12:31 AM
Hello sdners
I need help with a java udf
context udf : array of texts will be passed to udf
text1 : This is a purchase order number 111111....# and date is 10/02
text2: purchase order number 222..# and date is 10/03
text n...
In all these texts being passed to the udf,we need to extract the string : purchase order 11111...
so basically the substring needs to be extracted "purchase order 11111... " . Anything between purchase order... and #: the substring needs to be extracted.
The substring extracted is dynamic in length : purchase order ..... : can be of any length.
regards
Hi,
input text is : The purchase order number is 123456#
output : purchase order number is 123456
if the above is ur requirement then check with the below udf..it works!!
use cache parameter as value
public String find(String a,Container container)
{
//write your code here
String start_pos = "purchase order";
String end_pos = "#";
int s1 = a.indexOf(start_pos);
int s2 = a.indexOf(end_pos);
String output = a.substring(s1,s2);
return output;
}
srctext-->find->tgt
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Malini/Sridhar
Thanks to both of you.
Malini has understood the requirement correctly as her understanding of the question is correct although i have not tried her udf.
But Malini ,the field is repeating : I mean there can be many texts coming as the segment under which it comes is a repeating segment. You gave cache parameter as value ,but I guess since the field is repeating we need to give cache parameter as Context. Can you modify your functions as a context function instead of value ?
Regards
Hi Denny
Try this
public void returnPurchaseOrder(String[] input,ResultList result,Container container)
{
//write your code here
String output="";
for(int i=0;i<input.length;i++){
int start = input.indexOf('Purchase order');
int end = input.indexOf('#');
output = text1.substring(start,end);
}
result.addValue(output);
}
Thanks
Gaurav
HI Denny
Thanks for asking this i made a mistake in the code above. Corrected one is
public void returnPurchaseOrder(String[] input,ResultList result,Container container)
{
//write your code here
String output="";
for(int i=0;i<input.length;i++){
int start = input.indexOf("Purchase order");
int end = input.indexOf('#');
output = text1.substring(start,end);
}
result.addValue(output);
}
In Java when we say index of - it return position(integer) of a character or string.
indexOf( ' character' )
indexOf ( "String" )
In case source come as PURCHASE ORDER and sometime purchase Order we can use compareToIgnoreCase("Purchase order") that should solve the problem
Thanks
Gaurav
Hi Denny
This is a purchase order number 11111 #
in this "purchase order" is 11 but for your requirement to get only 1111 out of the above string you need to keep "purchase order number" into the code i provided above instead of "purchase order"
Secondly for your requirement of the above string you can incorporate
int start = input.toLowerCase().indexOf("purchase order");
Thanks
Gaurav
Hi,
I have modified my udf.
Hope it works 4r repeating segments.
Use cache parameter as context
public void find(String[] a,ResultList result,Container container)
{
//write your code here
String start_pos = "purchase order";
String end_pos = "#";
for(int i=0 ; i != a.length ; i++)
{
int s1 = a<i>.indexOf(start_pos);
int s2 = a<i>.indexOf(end_pos);
String output = a<i>.substring(s1,s2);
result.addValue(output);
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Denny
thanks for the clarification
you can try this
String out="";
for(int i=0;i<text1.length;i++){
int x = text1<i>.indexOf('#');
out = text1<i>.substring(0,x);
}
result.addValue(out);
Thanks
Gaurav
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
I am not sure but cant we identify in a text : a substring starting with purchase and ending with #
Purchase(wild card *) ends with #
Text1 : This is a purchase order number 111111#
Text2: Purchase order number 2222#
Text3 : This is an invoice but its purchase order number is 33333# and its invoice number is 44.
If we have texts like these passed to your udf ,then can we identify this substring ( Purchase order number ..) based on the logic : starts with purchase and everything before #?
I am not sure though.
Regards
Hi
Without the info of identifying we need to consider every case out here.
The above UDF code can be enhanced using any other string operation
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html
Thanks
Gaurav
Hi Denny,
Based on my understanding the output should be Purchase order should return the UDF .
If my understanding is right then the following udf return the Puchase order number.
import java.util.*;
String s="";
StringTokenizer parser = new StringTokenizer(a);
while (parser.hasMoreTokens()) {
String s1=parser.nextToken();
if(s1.endsWith("#")){
s = s1;
}
}
int k = s.length()-1;
return s.substring(0,k);
This will return the Puchase order number in a given any String ends with #.
for the above texts it will give the output as 111111
Regards
Sridhar Goli
Sridhar:
In your understanding of requirement :
Input : This is a purchase order number 11111 and invoice is 222
Outut : purchase order number 11111
Since this is a free form text ,it needs to be returned in target as : purchase order number 11111
and it needs to be a context function as it can repeat many time with different values as it comes under a repeating segment.
Regards
Hi Denny
can you provide more info on your requirement
In case you don't have context type UDF this is pretty easy to do
text1 = "11111#222"
for this x = text1.IndexOf('#');
String out ="";
out = text1.substring(0,x);
return out;
Thanks
Gaurav
.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
We will have list of texts which i have mentioned and we need to extract only the substring which tells the purchase order number and to specify the end of this substring there is a # coming ,so we need to extract the sub string : purchase order number......
Everything after purchase and before # needs to be extracted.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
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.