Skip to main content
Solved

Is there any transformer in FME that removes whitespace in between strings all at once apart from using a stringreplacer or attributetrimmer multiple times?

  • January 24, 2022
  • 7 replies
  • 1275 views

I have a data that contains whitespaces at the beginning, between and at the end. I have used an attributetrimmer to trim out the spaces at the beginning and end, but I am left with the spaces in between. Please, does anyone have an idea of how I can go about it because I can't keep using a stringreplacer repeatedly for this large dataset?

Best answer by geomancer

Your data contains strings like

Rijiyar   Ganji Islamiyya Primary      School

You ask for any transformer in FME that removes whitespace in between strings all at once.

 A single StringReplacer set to replace <space> with nothing, like @david_r​ and @Hans van der Maarel​ suggest, does remove all spaces, just like you ask, and gives

RijiyarGanjiIslamiyyaPrimarySchool

But probably you want to retain one space between words. This can also be accomplished with a single String Replacer, but in 'Replace Regular Expression' mode.

Consecutive_spaces 

Text to Replace[ ]{2,}   (this means 2 or more consecutive spaces)
Replacement Text: (put a single space here)

This results in

Rijiyar Ganji Islamiyya Primary School

Your sample data contains no spaces at the beginning or at the end, but you can use an AttributeTrimmer or the Trim-function in an AttributeManager to remove those spaces.

View original
Did this help you find an answer to your question?

7 replies

david_r
Celebrity
  • January 24, 2022

Does not a single StringReplacer set to replace <space> with nothing work?


No, I have tried that and it doesn't work.

 


redgeographics
Celebrity
Forum|alt.badge.img+49
balogunopeyemi1 wrote:

No, I have tried that and it doesn't work.

 

I'd agree with @david_r​ here, but if you can post a sample of your data we might be able to help you further.


Kindly find attached a sample of the data I have been having the challenge in. Thank you very much @Hans van der Maarel​ and @david_r​ for your contributions so far.


Forum|alt.badge.img+2
  • January 24, 2022

@balogunopeyemi1​ Thanks for including the SpatiaLite database example. You should be able to us StringReplacer with a regular expression "\\s+" and the replacement text <space> that will remove multiple consecutive spaces.

dialog


geomancer
Evangelist
Forum|alt.badge.img+47
  • Evangelist
  • Best Answer
  • January 24, 2022

Your data contains strings like

Rijiyar   Ganji Islamiyya Primary      School

You ask for any transformer in FME that removes whitespace in between strings all at once.

 A single StringReplacer set to replace <space> with nothing, like @david_r​ and @Hans van der Maarel​ suggest, does remove all spaces, just like you ask, and gives

RijiyarGanjiIslamiyyaPrimarySchool

But probably you want to retain one space between words. This can also be accomplished with a single String Replacer, but in 'Replace Regular Expression' mode.

Consecutive_spaces 

Text to Replace[ ]{2,}   (this means 2 or more consecutive spaces)
Replacement Text: (put a single space here)

This results in

Rijiyar Ganji Islamiyya Primary School

Your sample data contains no spaces at the beginning or at the end, but you can use an AttributeTrimmer or the Trim-function in an AttributeManager to remove those spaces.


Thanks @geomancer​ It worked perfectly well and performed what I wanted...Thanks everyone for your Contributions


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