on 05-30-2008 2:48 PM
Hi All,
I am trying to create a UDF for following functionality:
( Need to copy only 5 characters of an incoming data string(A) starting from a particular character(B) )
Input 1 ( Text/integer String) = A
Input 2 ( Split Start Place) = B
Output ( Split value string) = C
Example:
Incoming string(A) = '00112233445566778899'
Split start value(B) = '3'
Output (C) = '11223'.
Appreciate if you could let me know the code for it.
Thanks
Shirin
Use standard function "substring"
Regards,
Prateek
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Try this code,
String source = "00112233445566778899";
String checkChar = "3";
String target = "";
if(source.indexOf(checkChar) != -1)
target=source.substring(source.indexOf(checkChar)-4, source.indexOf(checkChar)+1);
System.out.println(target);
Change the code dynamically according to your requirement. I hardcoded the values.
Thanks,
Gujjeti
Hi Praveen and Soumya,
Thanks for the code. I am zero in Java programming. Both these codes are returning error messages and I have no idea how to corect it.
Apologies, not sounding rude, but am just helpless. If possible could you pass me the code which I could just cut and paste in the function box.
Thanks again for the replies.
Regards
Shirin
Hi shirin,
Create a new UDF without changing default options and put the following code in the UDF editor and map the input & output fields accordingly to the UDF in the mapping editor.
//--
String checkChar = "3"; //Fixed char
if(a.indexOf(checkChar) != -1 && a.indexOf(checkChar) >=4 )
return ( a.substring(a.indexOf(checkChar)-4, a.indexOf(checkChar)+1) );
else
return "Input String Doesnt have the expected char occurence (or) the occurence is before the 5 th position";
//--
If the fixed char is from source structure as input field, then change the first statement as,
String checkChar = b;
Means your UDF has two inputs a and b.
If it is not the case, then simply use the above code.
Thanks,
Gujjeti
User | Count |
---|---|
82 | |
11 | |
10 | |
8 | |
6 | |
6 | |
6 | |
6 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.