cancel
Showing results for 
Search instead for 
Did you mean: 

need udf based on the delimiter "."

giridhar_vegi
Participant
0 Kudos

Hi Experts,

               i need a UDF for splitting of a string based on the delimiter "." i have done with the following udf but it is not working with my delimiter. it is working with the ";" delimiter.

for (int i = 0; i < field1.length; i++)

{

          String tokens[] = field1[i].split(".");

         field1_out.addValue(tokens[0]);

         field2_out.addValue(tokens[1]);

         field3_out.addValue(tokens[2]);

sample input --Action.20150302.0101 so here i need to split it in to 3 strings so that i will do some validations on the timestamp.

please help me guys

Thanks

Giridhar

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member182412
Active Contributor
0 Kudos

Hi Giridhar,

Hareesh already given the answer, he is right but you can use below code instead of hard coding the string array values in your code.


public void split(String[] input, ResultList result, Container container) throws StreamTransformationException {

        String[] StrArray = input[0].split("\\.");

        int len1 = StrArray.length;

        for (int i = 0; i < len1; i++) {

            result.addValue(StrArray[i]);

        }

    }

Regards,

Praveen.

former_member184720
Active Contributor
0 Kudos

change it to String tokens[] = field1[i].split("\\."); and try?