Skip to Content
0
Former Member
Aug 12, 2009 at 12:47 PM

Message Mapping - Identify a number in a sting

31 Views

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