Skip to Content
avatar image
Former Member

UDF code needed for splitting data string

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

8 Answers

  • Best Answer
    May 30, 2008 at 01:52 PM

    Use standard function "substring"

    Regards,

    Prateek

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi,

      Create the UDF and select function as simple.

      And give the variable as A (the entire string) and B (Its a character where you want to take the substring)

      String s=a.substring('b',5);

      // here b is the starting character

      return s;

  • avatar image
    Former Member
    May 30, 2008 at 01:58 PM

    Hi,

    int l = A.index(b);

    String s=a.substring(l,5);

    return s;

    In the s variable you got the required output.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 30, 2008 at 02:12 PM

    Are you looking at removing leading zeroes and then extracting the 5 characters. Then you write a simple udf, to remove leading zeroes like this

    return a.replaceAll("^0+","");

    a is the input parameter.

    and then you can use the substrign function.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 30, 2008 at 02:14 PM

    Hi Srini,

    Send me those error messages..

    Regards,

    Soumya

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 30, 2008 at 02:32 PM

    Hi,

    try this code:

    // inputString: input string parameter
    // start_char: input string of the starting char
    
    int NUM_VALID_CHAR = 5; 
    int index_start = (inputString.indexOf("start_char") + 1) - NUM_VALID_CHAR;
    
    /*
    * I put a check if you have an input string where the starting char 
    * have an index less then 4. You can delete it if you don't need it.
    */
    if(index_start >= 0){
    	return inputString.substring(index_start, index_start + NUM_VALID_CHAR);
    }else{
    	
                    return inputString.substring(0 , NUM_VALID_CHAR+1);
    }
    

    Regards

    Emiliano

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 31, 2008 at 07:53 AM

    Hi Shiri,

    Try this UDF code

    String vals[] = A[0].split("3");

    for(int j=0; j<vals.length; j++)

    {

    result.addValue(vals[j]);

    }

    Thanks

    Vikranth

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 30, 2008 at 01:58 PM

    Hi,

    public String mapxxx(String a,Container container)

    {

    int b=3;

    if(a.length()>0)

    {

    String b=a.substring(3,5);

    return b;

    }

    else

    return a;

    }

    check this..

    correct me if wrong.

    Regards,

    Soumya

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jun 18, 2008 at 10:52 AM

    Hi,

    Thanks for all the replies. I keep on getting error messages for the UDF source code. But have manged to solve the issue using the existing standard graphical mapping functions.

    If anyone needs to know, do send me your comm id and I can send the screen shot of my mapping as I can not paste it here.

    Thanks once again everyone 😊

    Shirin

    Add comment
    10|10000 characters needed characters exceeded