Question

Remove carriage return / line feeds

  • 24 March 2015
  • 5 replies
  • 158 views

Badge
Dear FME community,

 

 

I have a single column wich contains carriage returns or line feeds. Is there a way to remove these signs, for example with the StringReplacer? Can anybody please help with the correct term in "Text to match".

 

 

I have three signs I want to replace with nothing (i.e. remove them):

 

- carriage returns / line feeds

 

- semicolons

 

- dollar signs

 

 

Kind regards

 

Thomas

 

 

5 replies

Badge +1
Hi Thomas, 

 

 

You can use \\n to search for carriage returns.

 

 

Owen
Badge +3
y0u can also use hexadecimal approach.

 

 

carriage return \\x0D and linefeed \\x0A etc.

 

 
Badge
Many thanks Owen and Gio! The StringSearcher with [\\r\\n\\$,;] works perfectly. Problem solved :)

 

 

Kind regards

 

Thomas
Badge +3
Dollarsign, carriagereturn and linefeeds must be escaped with a "\\".

 

should be:

 

 

Dollarsign must be escaped with a "\\".

 

carriagereturn and linefeeds: non-printable characters shorthands are (amongst others)

 

\\t matches a tab character , \\r a carriage return and \\n a linefeed

 

 

"\\r" is a carriage return.

 

"\\xFF" is non-Unicode. "uFFFF" is unicode. (where F s a hexadecimal character)

 

 

in "x0D" the "0D" is the ascii code for carriage return in hexadecimal etc.

 

 

 

Hope this satisfies the disgruntlled... ;)

 

 

If you don't believe me, look it up on any regexp info site (of wich there are zillions).

 

 

 
Badge +7

I used a TestFilter to examine some CSV data I have where one field contains Carriage Returns and/or Line Feeds. I created separate Output Ports for "Contains RegEx \\r" and "Contains RegEx \\n" which revealed that I had BOTH types in the data. Therefore I need to replace both. So in StringReplacer my Mode is "Replace Regular Expression" and my "Text To Replace" is (\\r|\\n).

Out of 330,000 features, only 73,000 contained CR and/or LF. However, it is 9 seconds quicker to JUST use StringReplacer versus Tester and StringReplacer where the Tester is only sending features to StringReplacer that need fixing.

Reply