Skip to Content

Passing required characters from a multiple values in a Source filed to Target field

Hello All,

Could you help me in passing the required characters from a source field value to Target field. But the challenge here is the Source field value consists of multiple values and not fixed

Ex1: <Sourcefield>2210-E,2210-7,3320-0</Sourcefield> ===> <Targetfield>E70</Targetfield>

Ex2: <Sourcefield>2345-9,2210-B,5467-D,3456-7</Sourcefield> ===> <Targetfield>9BD7</Targetfield>

Could you help with UDF to get this done.Any help would be much appreciated.

Thanksâ„śgards

Moulali P

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • Best Answer
    Posted on Aug 04, 2020 at 06:26 AM

    You can use regular expressions to extract the values. A valid regex could look like \d{4}-(.),?
    Check the following link for an example: https://regex101.com/r/20IUir/1

    Then write a small UDF which uses this regex to extract the information:

    String input = "2345-9,2210-B,5467-D,3456-7";
    String output = "";
    Pattern pattern = Pattern.compile("\\d{4}-(.),?");
    Matcher matcher = pattern.matcher(input);
    
    while (matcher.find()) {
         output += matcher.group(1);
    }
    return output;
    

    You can find a running demo here: http://tpcg.io/OiGw76H0

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 05, 2020 at 07:39 AM

    Hello Raffael,

    Thanks for your reply, It worked :)

    Can you assist me if the 4 digit input pattern is Alphanumeric ex: String input="2C4D-9,ABGH-B,5467-D,F45C-7";

    Thanks again for your assistance :)

    Regards

    Moulali P

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 05, 2020 at 09:15 AM

    Yes Its working . Thanks for the Help

    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.