Skip to main content
Solved

Stringreplacer

  • December 4, 2014
  • 6 replies
  • 42 views

Hi all,

 

 

I have a column containing the coordinates information such as:

 

54960000.0 643600000.63 0.0

 

....

 

 

I am wondering to know if there is any way to extract the first four integers for the X and Y values.

 

At the end, I need to have the value like "5496,6436"

 

 

One possibility is for example using attributesplitter. But Is it also possible to use stringreplacer doing it only in one step?

 

 

Thank you,

 

Mani

Best answer by takashi

HI Mani,

 

 

Try the StringReplacer with this setting.

 

Text to Match: ^([0-9]{4})[^\\s]*\\s+([0-9]{4}).*$

 

Replacement Text: \\1,\\2

 

Use Regular Expressions: yes

 

 

Takashi
View original
Did this help you find an answer to your question?
This post is closed to further activity.
It may be a question with a best answer, an implemented idea, or just a post needing no comment.
If you have a follow-up or related question, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

6 replies

david_r
Evangelist
  • December 4, 2014
Hi,

 

 

you can use the StringSearcher, e.g. like this for the "x" attribute:

 

 

 

 

Then do the same once more for the "y" value.

 

 

David

  • Author
  • December 4, 2014
Hi David and thank you.

 

 

well I think the same can be using attributesplitter and putting 4s to split the attribute but because I have x,y and z all together separated by space so I need first to split them into x and y and then either use your way or attributesplitter and then again concatenate them. Yes. This can be done.

 

 

But this question just came in my mind if this is possible to do these all in one step like searching for a series of numbers(dynamic) ended with space and then replace them with comma ",".

 

 

Thanks,

 

Mani

takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • Best Answer
  • December 4, 2014
HI Mani,

 

 

Try the StringReplacer with this setting.

 

Text to Match: ^([0-9]{4})[^\\s]*\\s+([0-9]{4}).*$

 

Replacement Text: \\1,\\2

 

Use Regular Expressions: yes

 

 

Takashi

parashari
Forum|alt.badge.img+2
  • December 5, 2014
Hi,

 

You can use String Formatting code using Python scripting. Here is a case:

 

 

>>> '%.2f' % 1.234

 

'1.23'

 

>>> '%.2f' % 5.0

 

'5.00'

 

This will work out with python 3 syntax.

 

You can changethe number '%.*f%' according to your usage. (:

  • Author
  • December 5, 2014
Thank you Takashi :)

takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • December 5, 2014
In this case, the AttributeCreator with FME String Functions could also be useful.

 

If the source string (space-separated coordinates) is stored by an attribute called "coord", for example, this expression written in the "Value" column of an AttributeCreator returns the required string.

 

@Left(@Value(coord),4),@Left(@GetWord(@Value(coord),1),4)

 

 

This may be easier to understand than the regular expression.

 

See here to learn more about FME String Functions.

 

FME Workbench Transformers > FME String Functions (http://docs.safe.com/fme/html/FME_Transformers/Default.htm#transformer_parameters/StringFunctions.htm)

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