Skip to main content
Best Answer

modyfing attribute values

  • May 15, 2018
  • 4 replies
  • 6 views

Forum|alt.badge.img

I have attribute zip code, where all values looks in this form 12345 how can I transform them into this form 123 45?

My idea was to split it using StringReplacer where I would replace \\d{5} by \\d{3} \\s \\d{2}, however I don't know how can I create new attribute which base on the old zip code attribute (12345).

Are there any other ways to do it?

Best answer by takashi

Hi @vid, I think the StringReplacer is a right way. If you need to preserve the original value, copy the original value to a new attribute with the AttributeCopier, then modify it with the StringReplacer transformer.

Parameters Setting Example:

  • Mode: Replace Regular Expression
  • Text to Replace: (\\d\\d)$
  • Replacement Text: \\1 (a single space and '\\1')

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

4 replies

takashi
Celebrity
  • Best Answer
  • May 15, 2018

Hi @vid, I think the StringReplacer is a right way. If you need to preserve the original value, copy the original value to a new attribute with the AttributeCopier, then modify it with the StringReplacer transformer.

Parameters Setting Example:

  • Mode: Replace Regular Expression
  • Text to Replace: (\\d\\d)$
  • Replacement Text: \\1 (a single space and '\\1')


takashi
Celebrity
  • May 15, 2018

Hi @vid, I think the StringReplacer is a right way. If you need to preserve the original value, copy the original value to a new attribute with the AttributeCopier, then modify it with the StringReplacer transformer.

Parameters Setting Example:

  • Mode: Replace Regular Expression
  • Text to Replace: (\d\d)$
  • Replacement Text:  \1   (a single space and '\1')

Alternatively, you can also use the @ReplaceRegEx function to directly create a new zip code from the original code, in a parameter field such as 'Attribute Value' field in the AttributeCreator. e.g.

 

@ReplaceRegEx(@Value(_original_zip_code),"(.+)(\d\d)$",\1 \2)

 


Forum|alt.badge.img
  • Author
  • May 15, 2018

Hi @vid, I think the StringReplacer is a right way. If you need to preserve the original value, copy the original value to a new attribute with the AttributeCopier, then modify it with the StringReplacer transformer.

Parameters Setting Example:

  • Mode: Replace Regular Expression
  • Text to Replace: (\\d\\d)$
  • Replacement Text: \\1 (a single space and '\\1')

Thank you!

 

 


erik_jan
Contributor
Forum|alt.badge.img+26
  • Contributor
  • May 15, 2018

This would work in an AttributeCreator (or AttributeManager):

@Substring(@Value(zip),0,3) @Substring(@Value(zip),3,2)