Skip to Content
author's profile photo Former Member
Former Member

string separation

All,

I'm receiving a string ##FName#LName## ,I need to send FName to one field and LName to another fileds.

Please provide me with some inputs.

Thanks,

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Oct 12, 2010 at 02:28 PM

    You can use 2 seperate UDF to extract the 2 fields. for the leading ##, you use substring and ignore the first two values(##) and then split by #.

    please use the UDF mentioned below.

    use this UDF

    for first name

    public String StringSplit(String var1, Container container) throws StreamTransformationException{
    int len = var1.length();
    var1= var1.substring(2,len);
    String arr[] = var1.split("#");
    return arr[0];

    for last name

    public String StringSplit(String var1, Container container) throws StreamTransformationException{
    int len = var1.length();
    var1= var1.substring(2,len);
    String arr[] = var1.split("#");
    return arr[1];

    Regards,

    Srinivas

    Edited by: Srinivas on Oct 12, 2010 10:59 PM

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 12, 2010 at 03:07 PM

    Hi

    You can use REGEX in the UDF to achieve this

    Include 2 parameters in the UDF Say

    a - [input (##Ram#Kumar##) ]

    b - [Index values for first name (2) and last name (4)]

    Imports: java.util.regex.*;

    Parameters:

    a, b

      int indexVal = Integer.parseInt(b); 
     String pattern = "(##)(.*)(#)(.*)(##)";   // first (.*) is first name - index val is 2   and last name index value is 4
     Pattern d = Pattern.compile(pattern);
     Matcher m = d.matcher(a);
                if(m.find())
                {
                    a = m.group(indexVal);
                  
                }
    
    return a;
    

    Use the same code for different fields by changing the constant(index values) in the mapping.

    you can refer the below forum discussion further as srini suggest...

    Separator UDF

    Regards

    Ramg

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 12, 2010 at 04:09 PM

    Hi Pushpa.

    Use one UDF and two parameters one for string and the other the position,

    value : String (e.g ##FName#LName)

    pos : Position that you want.

    String result = "";
    String array01[] = value.split("##");
    String array02[] = array01[1].split("#");
    result = array02[pos];
    return result;
    
    

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.