Skip to main content
Question

Add blank space in text string


Forum|alt.badge.img

Hi!

I am kind of new to FME so this must be a simple issue to solve for anyone in here.

I have a xls-file with zip codes, 5 characters together. I want to add a blank space between the third and the fourth character. I just can´t find a simple way to do it with my limited knowledge...

Thanks,

Tobias

17 replies

redgeographics
Celebrity
Forum|alt.badge.img+50

You could use an AttributeSplitter with format string 3s2s, this creates a list with 2 elements, let's call them _list{0} and _list{1}. The first one holds the first three characters, the second one the last two.

Then an AttributeCreator that creates a new attribute which is the value of _list{0}, then a space and then the value of _list{1}


ebygomm
Influencer
Forum|alt.badge.img+39
  • Influencer
  • September 8, 2016

Or just use the following formula in an attributecreator

@Left(@Value(zip),3) @Right(@Value(zip),2)


mark2atsafe
Safer
Forum|alt.badge.img+44
  • Safer
  • September 8, 2016

Or you could use an AttributeManager (or AttributeCreator) create a new attribute, open the text editor dialog, and enter:

@Left(@Value(zip),3@Right(@Value(zip),2)

Obviously there is a space between the two of those functions.


mark2atsafe
Safer
Forum|alt.badge.img+44
  • Safer
  • September 8, 2016
ebygomm wrote:

Or just use the following formula in an attributecreator

@Left(@Value(zip),3) @Right(@Value(zip),2)

Ha! You beat me to it by 16 seconds!

 

 


erik_jan
Contributor
Forum|alt.badge.img+18
  • Contributor
  • September 8, 2016

Another way is using the AttributeCreator with the expression for the new value:

@Substring(@Value(test),0,3) @Substring(@Value(test),3,2)

This assumes the old attribute to be "test".


david_r
Celebrity
  • September 8, 2016

You can also use a StringReplacer, then you only need one transformer:

Replacement text has a space between \\1 and \\2


redgeographics
Celebrity
Forum|alt.badge.img+50
david_r wrote:

You can also use a StringReplacer, then you only need one transformer:

Replacement text has a space between \\1 and \\2

I was trying the StringReplacer too but ran into the issue that it didn't seem to work as documented in this case, the docs suggest that that parts list starts at 0 and requires \\\\ instead of \\

 

 


takashi
Influencer
  • September 9, 2016
redgeographics wrote:
I was trying the StringReplacer too but ran into the issue that it didn't seem to work as documented in this case, the docs suggest that that parts list starts at 0 and requires \\ instead of \

 

 

The help on the StringReplacer says:

 

If the replacement text contains & or \0, then it is replaced in the substitution with the portion of string that matched the regular expression.

 

If replacement text contains \#, where # is a digit between 1 and 9, then it is replaced in the substitution with the portion of string that matched the n-th parenthesized subexpression of the regular expression.

 

 

The first paragraph is unreliable. If it was true, this setting for this case should work as expected.

 

  • Text to Match: ^...
  • Replacement Text: &<space> or \0<space>
However, in my test with FME 2016.1.1 build 16609, & and \0 didn't work as documented. @Mark2AtSafe, could you please check this?

 

In addition, this example within the help doc may not be correct. I think the Replacement Text should be --\0-\0, if the first paragraph was correct.

 

Source String: Bobby
Text to Find: b*y
Replacement Text: --\\0-\\0
Use Regular Expression: yes
Case Sensitive: yes
Result: Bo--bby-bby

Forum|alt.badge.img
  • Author
  • September 9, 2016

Looks like all the ways I tried could have worked if I just had done it right!

Thanks to all of you!


david_r
Celebrity
  • September 9, 2016
redgeographics wrote:
I was trying the StringReplacer too but ran into the issue that it didn't seem to work as documented in this case, the docs suggest that that parts list starts at 0 and requires \\ instead of \

 

 

@redgeographics, the secret is to ignore that section and read the next...

 

 

I agree, the documentation needs to be reviewd on this subject. In FME 2016.1 it says:

 

If the replacement text contains & or \0then it is replaced in the 
substitution with the portion of string that matched the regular
expression.
\0 or & does not seem to work for me at all, just as Takashi says.

 


takashi
Influencer
  • September 9, 2016
david_r wrote:
@redgeographics, the secret is to ignore that section and read the next...

 

 

I agree, the documentation needs to be reviewd on this subject. In FME 2016.1 it says:

 

If the replacement text contains & or \0then it is replaced in the 
substitution with the portion of string that matched the regular
expression.
\0 or & does not seem to work for me at all, just as Takashi says.

 

I remember that & and \0 worked as documented in FME 2015. Perhaps it's a bug in FME 2016...

 


david_r
Celebrity
  • September 9, 2016
takashi wrote:
I remember that & and \\0 worked as documented in FME 2015. Perhaps it's a bug in FME 2016...

 

I just tested in FME 2015 and confirm that \\0 works there.

 

Could possibly be a regression due to the homogenization efforts of the regex engine, @daleatsafe

 


redgeographics
Celebrity
Forum|alt.badge.img+50
david_r wrote:
@redgeographics, the secret is to ignore that section and read the next...

 

 

I agree, the documentation needs to be reviewd on this subject. In FME 2016.1 it says:

 

If the replacement text contains & or \0then it is replaced in the 
substitution with the portion of string that matched the regular
expression.
\0 or & does not seem to work for me at all, just as Takashi says.

 

You know, there is a reason why my mind starts boggling when I need to use regexes... 

 

 


mark2atsafe
Safer
Forum|alt.badge.img+44
  • Safer
  • September 9, 2016
takashi wrote:
The help on the StringReplacer says:

 

If the replacement text contains & or \0, then it is replaced in the substitution with the portion of string that matched the regular expression.

 

If replacement text contains \#, where # is a digit between 1 and 9, then it is replaced in the substitution with the portion of string that matched the n-th parenthesized subexpression of the regular expression.

 

 

The first paragraph is unreliable. If it was true, this setting for this case should work as expected.

 

  • Text to Match: ^...
  • Replacement Text: &<space> or \0<space>
However, in my test with FME 2016.1.1 build 16609, & and \0 didn't work as documented. @Mark2AtSafe, could you please check this?

 

In addition, this example within the help doc may not be correct. I think the Replacement Text should be --\0-\0, if the first paragraph was correct.

 

Source String: Bobby
Text to Find: b*y
Replacement Text: --\\0-\\0
Use Regular Expression: yes
Case Sensitive: yes
Result: Bo--bby-bby
Checking it out now. I wonder if we are misinterpreting the help, and that \0 is a special case. Sometimes we're too subtle for our own good. It does sound bad that it did have an effect in 2015, so I am checking it all out and will report back.

 

 


mark2atsafe
Safer
Forum|alt.badge.img+44
  • Safer
  • September 9, 2016
david_r wrote:

You can also use a StringReplacer, then you only need one transformer:

Replacement text has a space between \\1 and \\2

OK. Some findings...

 

 

1) I found some info that said:

 

You can use \\0 as a placeholder for the whole regex match, and \\1 through \\9 for the text matched by one of the first nine capturing groupsSo I think we need to update the doc to be more clear that the parts list starts at 1, and that 0 is the whole of the match.

 

 

2) The doc is also wrong in saying you need to use \\\\0 - I guess at some point you needed the first \\ as an escape character. Not any more.

 

 

3) It (\\0) no longer works in 2016.

 

 

I'll file all of these issues with our devs and let you know when they are fixed.

 


mark2atsafe
Safer
Forum|alt.badge.img+44
  • Safer
  • September 9, 2016
mark2atsafe wrote:
OK. Some findings...

 

 

1) I found some info that said:

 

You can use \\0 as a placeholder for the whole regex match, and \\1 through \\9 for the text matched by one of the first nine capturing groupsSo I think we need to update the doc to be more clear that the parts list starts at 1, and that 0 is the whole of the match.

 

 

2) The doc is also wrong in saying you need to use \\\\0 - I guess at some point you needed the first \\ as an escape character. Not any more.

 

 

3) It (\\0) no longer works in 2016.

 

 

I'll file all of these issues with our devs and let you know when they are fixed.

 

PR72151 (functionality failure) and PR72152 (documentation improvements)

 

 


roggarbett
Participant
Forum|alt.badge.img
  • Participant
  • June 20, 2018
mark2atsafe wrote:

Or you could use an AttributeManager (or AttributeCreator) create a new attribute, open the text editor dialog, and enter:

@Left(@Value(zip),3@Right(@Value(zip),2)

Obviously there is a space between the two of those functions.

Just used this to put a . in a text string to create the decimal space to turn the data into currency. The original file was a flat text string and I had to extract the amount in p's (pennies) and then turn it into £'s so that i could email the (file producers) the amount as a check to ensure the correct amount of money was being transferred.

 

 


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