Standard function for specified return
Hi,
I have an issue I want your help with.
This is only valid if numbers 5 or 6 are in the input.
I want to return the last 2 digits from the input parameter. for example. Input: 123456. Output: 56.
Or if there's only 12345 I want to return 5.
I can't do any substring because the input parameter could be whatever. example. 125. Example: 6.
Summary. I need a function that returns the last digits of the input parameter only if the input includes 5 or 6, or both.
Hope you understand.
Regards.
Baskar Gopalakrishnan replied
Below UDF handles all possible inputs as per your requirement.
public String returnLast2Digits(String var1, Container container) throws StreamTransformationException{ if( var1.length()>1){ String str2 = var1.substring(var1.length()-2,var1.length()); if(str2.substring(0,1).equals("5")&& str2.substring(1,2).equals("6")){ return str2; } else if(str2.substring(1,2).equals("5") || str2.substring(1,2).equals("6")){ return str2.substring(1,2); } else{ return ""; } }else{ if(var1.equals("5") || var1.equals("6")){ return var1; } else{ return ""; } } }
Edited by: Baskar Gopal on May 17, 2011 2:54 PM