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
  • 119 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
View original
Did this help you find an answer to your question?

4 replies

danilo_fme
Evangelist
Forum|alt.badge.img+44
  • Evangelist
  • 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
Influencer
  • 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
  • November 26, 2018
takashi wrote:

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
Influencer
  • November 26, 2018
takashi wrote:

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.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings