Skip to Content

split the string

Hi ,

I need to split the phone number string into country code and phone number

Source                    Target

+44|9742744480 = first field 44 second field = 9742744480

I tried to use sub string function it will get fail when +1|9742744480 or +142|9742744480  will come .

please suggest.

Regards,

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    Oct 19, 2015 at 10:21 AM

    you have to use split.

    you can try below snippet to get the data in udf.

    String[] output = new String[3];

      output = input.split("[+|]");

    output[1] and output[2] will have 44 and 9742744480 respectively.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 19, 2015 at 10:55 AM

    Hello Vishnu ,

    1. How may different company codes you might be receiving?

    Is that fixed? Based upon that you have to do mapping like IF-then(Sub String) or you can use UDF also.

    But first you should be aware how many different kinds of country codes you will be receiving.

    2. Another approach will be to tell your source system to send a constant digit county code like 3 digtis always for you to use Sub string.

    For e.g. :

    +142 = +142

    +44 = +044

    +1 = +001

    Thanks.

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 21, 2015 at 07:21 AM

    Hi Muni,

    If I need Number with Multiple occurrence do I need to change the execution type and code.

    String[] output =new String[3];

    output= var1.split("[+|]");

    return output[1];



    String[] output =new String[3];

    output= var1.split("[+|]");

    return output[2];

    Regards,

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 21, 2015 at 08:57 AM

    Hello Vishnu,

    The country code in general can differ from 1 to 4 digits, so i suggest you to refer table T005K table in SAP for these details and apply some look up table or rfc call you can design with your feasibility.

    Hope you have country in the payload to proceed in determining this details.

    Cheers

    Harsha

    Add comment
    10|10000 characters needed characters exceeded