Six Stars

How to remove hypen for the string values less than 9 and for 9 we have to keep the string value as it is

Hello folks,

I have a case where my string value is something like this whose length is 9. 

12345-6789

In this case I have to keep the same value as it is.

 

But when I have the string value 12-23 or 8765-768 I have to remove the hypen(string length is less than 9)

 

I want to format like above. Can someone please help as part of this. 

I have the formula like this.

StringHandling.LEN(Post_Formatting.BILLED_COMPANY_ZIP)== 9
? Post_Formatting.BILLED_COMPANY_ZIP : Post_Formatting.BILLED_COMPANY_ZIP.replaceAll("-", "")

 

But it is not working.

 

Regards,

Deepak

Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Six Stars

Re: How to remove hypen for the string values less than 9 and for 9 we have to keep the string value as it is

Hi Kiran,

 

Since in your condition it does not affect the string values more than 9, I did not use it,

 

Instead i have just tweaked my formula as below and it worked.

StringHandling.LEN(LP_Z_SERVICE_ADDRESS.ZIP)== 10
? LP_Z_SERVICE_ADDRESS.ZIP : LP_Z_SERVICE_ADDRESS.ZIP.replaceAll("-", "")

 

But thanks for your kind response on this.

 

Regards,

Deepak

8 REPLIES
Fifteen Stars

Re: How to remove hypen for the string values less than 9 and for 9 we have to keep the string value as it is

12345-6789 is not a String of length 9, it is of length 10. Your code says....

 

"When the String is length 9, leave it alone. When it is not length 9 (either less than 9 or greater than 9), remove all '-' characters"

 

I don't think that is what you want is it?

 

Can you tell us what you want with examples? Make sure they are accurate examples.

Rilhia Solutions
Six Stars

Re: How to remove hypen for the string values less than 9 and for 9 we have to keep the string value as it is

I think I got the mistake what I am instructing Talend through below code.

 

StringHandling.LEN(Post_Formatting.BILLED_COMPANY_ZIP)== 9
? Post_Formatting.BILLED_COMPANY_ZIP : Post_Formatting.BILLED_COMPANY_ZIP.replaceAll("-", "")

 

I will correct this as 

StringHandling.LEN(Post_Formatting.BILLED_COMPANY_ZIP)== 10
? Post_Formatting.BILLED_COMPANY_ZIP : Post_Formatting.BILLED_COMPANY_ZIP.replaceAll("-", "")

 

Requirement is:

When The string has 9 digit value and in between it has hypen(so it is 10 length as you said) I want keep this as it is, else remove the hypen.

 

Thanks for the reply 

Six Stars

Re: How to remove hypen for the string values less than 9 and for 9 we have to keep the string value as it is

hi,

please find the attachment and solution. if its correct give as resolved and kudos.

 

StringHandling.LEN(row4.hypen_data<9?StringHandling.EREPLACE(row4.hypen_data,"-",""):row4.hypen_data

 

Thanks

Venkata Kiran

Fifteen Stars

Re: How to remove hypen for the string values less than 9 and for 9 we have to keep the string value as it is

That doesn't cater for over 10 characters? Is that possible? What would be the rule if that did happen?

 

Rilhia Solutions
Six Stars

Re: How to remove hypen for the string values less than 9 and for 9 we have to keep the string value as it is

There are only 2 cases, 

One if the string has 9 digits and in between one Hypen then keep as it is.

 

If it is lesser than 9 digits then, we have to remove hypen.

 

The above is the rule.

Fifteen Stars

Re: How to remove hypen for the string values less than 9 and for 9 we have to keep the string value as it is

Your update should work then. Have you tried it?

 

Rilhia Solutions
Six Stars

Re: How to remove hypen for the string values less than 9 and for 9 we have to keep the string value as it is

is my solution correct ?

Six Stars

Re: How to remove hypen for the string values less than 9 and for 9 we have to keep the string value as it is

Hi Kiran,

 

Since in your condition it does not affect the string values more than 9, I did not use it,

 

Instead i have just tweaked my formula as below and it worked.

StringHandling.LEN(LP_Z_SERVICE_ADDRESS.ZIP)== 10
? LP_Z_SERVICE_ADDRESS.ZIP : LP_Z_SERVICE_ADDRESS.ZIP.replaceAll("-", "")

 

But thanks for your kind response on this.

 

Regards,

Deepak