Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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

Labels (1)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

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

View solution in original post

8 Replies
Anonymous
Not applicable
Author

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.

Anonymous
Not applicable
Author

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 

Anonymous
Not applicable
Author

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


Hypen.PNG
Anonymous
Not applicable
Author

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

 

Anonymous
Not applicable
Author

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.

Anonymous
Not applicable
Author

Your update should work then. Have you tried it?

 

Anonymous
Not applicable
Author

is my solution correct ?

Anonymous
Not applicable
Author

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