Skip to main content
Solved

Replace space with specific character based on the position of the space into the attribute

  • November 25, 2018
  • 4 replies
  • 152 views

boubcher
Contributor
Forum|alt.badge.img+11

Hello there I

I have an attribute with the values like this (24 16 17.2) or this ( 25 7 17.2) we need to replace the first space with a letter A and second space with letter B and add letter W at the end we should get a result like this (24A16B17.2W) and this ( 25A7B17.2W) for the second case

Any idea, please

Thanks

 

Best answer by takashi

I would use the StringReplacer with this setting.

  • Mode: Replace Regular Expression
  • Text to Replace: ^(\\S+)\\s(\\S+)\\s(.+)$
  • Replacement Text: \\1A\\2B\\3W
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

danilo_fme
Celebrity
Forum|alt.badge.img+51
  • Celebrity
  • 2077 replies
  • November 25, 2018

Hi @boubcher

I created here a example with your case:

1) Use the AttributeManager to created these two situations of Attributes

2) Split the Attributes and concactenate the values of the lists:

3) Results in FME Data Inspector:

 

Attached the Workspace Workspace_Replacer.fmw

 

Thanks,

Danilo

 

 


takashi
Celebrity
  • 7843 replies
  • Best Answer
  • November 25, 2018

I would use the StringReplacer with this setting.

  • Mode: Replace Regular Expression
  • Text to Replace: ^(\\S+)\\s(\\S+)\\s(.+)$
  • Replacement Text: \\1A\\2B\\3W

boubcher
Contributor
Forum|alt.badge.img+11
  • Author
  • Contributor
  • 212 replies
  • November 26, 2018

I would use the StringReplacer with this setting.

  • Mode: Replace Regular Expression
  • Text to Replace: ^(\\S+)\\s(\\S+)\\s(.+)$
  • Replacement Text: \\1A\\2B\\3W

@takashi

Thanks Takashi I am new to those expressions could please let me know how this work and how do you come up with the replacement text format

Thanks again

 


takashi
Celebrity
  • 7843 replies
  • November 26, 2018

I would use the StringReplacer with this setting.

  • Mode: Replace Regular Expression
  • Text to Replace: ^(\\S+)\\s(\\S+)\\s(.+)$
  • Replacement Text: \\1A\\2B\\3W

There are many resources about Regular Expressions. e.g.