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

10|10000 characters needed characters exceeded

### Related questions

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;

10|10000 characters needed characters exceeded
• 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 :

10|10000 characters needed characters exceeded

Hi

I use the code above and it's work...only put a parameter call "text" is a simple function.

• 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,

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)

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