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

Message Mapping - Identify a number in a sting

Hello Guys,

There is a requirement to perform a conversion based on its length.

If the length of the incoming field is less than or equal to 20 characters pass the string directly to the target field.

If the length is more than 20 then find the number of excess characters and remove that many number of characters from the string before the first occuranace of number in the string to make the total length as 20 chars.

As an example, lets say if I have a string with a length of 22 like this " I have 4 books at home"

In the string 2 chars have to be removed before the number 4, so that it has to look like "i hav4 books at home" which of length 20 char.

Some more examples :

"I have 14 keys and 1 pen" should be converted to "I h14 keys and 1 pen" (4 excess chars "ave " has been removed)

Have used this UDF and many combinations but that didn't work :

____________________________________________________________________________________________

public String test2(String STREET1,Container container){ //STREET1 is the incoming field

int input = STREET1.length();

int Length = 30;

int a,b,c;

int Loc = -1;

String str = "";

String str1, str2 = "";

if(input<=30)

{

str = STREET1;

}

//else

// {

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

{

if (Character.isDigit(STREET1.charAt(i)))

{

Loc = i;

}

}

// No digit found, so truncate to 30 length streetStr

if (Loc == -1)

{

str = STREET1;

}

// Digit found

else

{

a = input - Length;

b = Loc - a;

c = input - Loc;

str1 = STREET1.substring(0,b-2);

str2 = STREET1.substring(Loc,c);

str = str1" "str2;

}

return str;

-_________________________________________________________________________________________________-

Please correct the code or provide a workaround.... Thanks

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Aug 12, 2009 at 01:19 PM

    Hello,

    this should be your code. I make a test with "I have 14 keys and 1 pen" and my result is "I h14 keys and 1 pen".

    Regards, Björn

    int input = text.length();

    int Length = 20;

    int a,b,c;

    int Loc = -1;

    String str = "";

    String str1, str2 = "";

    if(input<=Length)

    {

    str = text;

    return str;

    }

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

    {

    if (Character.isDigit(text.charAt(i)))

    {

    Loc = i;

    break;

    }

    }

    // No digit found, so truncate to 30 length streetStr

    if (Loc == -1)

    {

    str = text.substring(0,Length);

    }else

    {

    a = input - Length;

    b = Loc - a;

    c = Length - Loc;

    str1 = text.substring(0,b);

    str2 = text.substring(Loc,input);

    str = str1""str2;

    }

    return str;

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 12, 2009 at 03:02 PM

    Hi Bjorn,

    There is not much change in the code. Even after implementing the new code,

    I am getting the same errors as earliier. 3 errors are displayed which has the same description.

    Error Desc :

    C:/usr/sap/IDV/DVEBMGS01/j2ee/cluster/server1/./temp/classpath_resolver/Map0d3b3110875011deaa330018fe866e58/source/com/sap/xi/tf/_SAP_DESADV_DELVRY05_TO_VDA_CustomerDelivery_.java:1080: unreachable statement public static void main(String[] args) throws Exception{/!_$ClNRep_/_SAP_DESADV_DELVRY05_TO_VDA_CustomerDelivery_ st = new /!_$ClNRep_/_SAP_DESADV_DELVRY05_TO_VDA_CustomerDelivery_(); st.testExecute(); }

    Please suggest, Thanks

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 12, 2009 at 04:45 PM

    Swetha,

    I have not used such a declaration anywhere in the UDF, but still the error is referring the st.testexecute method and the public String argss[]. No idea about this strange behaviour.

    Thanks,

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Vuppala,

      The function is working correct only. I think you are not sending any input parameter. It should like this.Create a value udf and name it is IdentifyString with one input parameter text. Then add this code:

      Imports: java.;*

      public String IdentifyString(String text,Container container)

      //write your code here

      Add the whole code given by him.

      Then it should get the required output. The only thing you wrong is I think you are not passing any input parameter.

      Regards,

      ---Satish

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.