Skip to Content
Former Member
Jul 31, 2012 at 06:37 AM

How to split a name in two using UDF


Hi Experts,

I have a situation here. In need to split the name into two sub names and take the last name as output.

For example, if i take the name 'Sachin Tendulkar' as input i should get the output as Tendulkar. For this i have written the code as shown below.

String[] tokens = str.split("\\s"); /str is input/

String fin=tokens[1];

return fin;

I am getting the output as Tendulkar. But when the input is coming without a delimiter like 'sachinTendulkar" i am getting error.Then the ouyput should be none. and also when ever the name comes has sachin Ramesh Tendulkar the output should come as 'Ramesh Tendulkar' and not 'ramesh'.

Or is there any way directly to do mapping. I hope you understood my problem.