Skip to main content

I'm new to FME so sorry for a noob question.

I have a text file that is in the below format. How can I replace the characters with an index of 15:15, 25:25, and 30:30 with just the '|' character (pipe)? There are only spaces in now. I have been trying to use StringReplacer and set the "Text to match" with @substring ( , 15, 15) but it doesn't work. Do I have to do each replace with it's own transformer or is it possible I can also do this with one StringReplacer?

Thank you in advance!

Characters 1:1415:15Characters 16:2425:25Characters 26:2930:30Character 31:31XXXXXXXXXXXXXX

 

XXXXXXXXX

 

XXXXX

XXXXXXXXXXXXXX

XXXXXXXXX

XXXX

X

 

I am assuming that the characters in the other indices contain spaces, so you can't just use a stringReplacer with space and pipe.

 

You can build a new attribute with the text editor @Substring(@Value(attr),0,14)|@Substring(@Value(attr),15,9)|@Substring(@Value(attr),25,4)|@Substring(@Value(attr),30,1)

 

 

where attr is the attribute containing the original string.

 

 

Note: Substring in the text editor work with the starting index (begining at 0) and number of characters to extract, not ending index like the SubStringExtractor transformer.

Agree. To add to @jdh's answer, you have to be case sensitive for the function name. @substring won't work, @Substring is correct.

Alternatively, you can still use the StringRepalcer with 'replace regular expression' mode.

  • Text to Match: ^(.{14}).(.{9}).(.{4}).(.)$
  • Replacement Text: \\1|\\2|\\3|\\4
  • Use Regular Expressions: yes

Awesome, thank you so much!! Really appreciate it!


@mwilchek

That would make you having count your strings. Lucky for you it isn't like a 10000 long or so.

Do away whit that!

Use in stringreplacer, regexp mode.

text to match :

(?:(\\d+:\\d+)) (\\d+):\\2

text to replace:

\\1|

Clearly more elegant.. ;)


Reply