Skip to main content
Solved

Concatenate list values

  • November 29, 2013
  • 1 reply
  • 38 views

farfar
Contributor
Forum|alt.badge.img+11
Hi all,

 

Generalty i use ListConcatenator to concatenate ALL list items. I need to concatenate list  items without the first item. Is there a specific transformer that can i use? 

 

Thanks an advance.

 

 

FarFar

Best answer by takashi

Hi,

 

 

I would apply Itay's 1st approach with a StringReplacer after concatenating.

 

Assume the separate character is a comma, the StringReplacer parameter settings are:

 

Attributes: _concatenated

 

Text to Find: ^[^,]*(,(.+))?$

 

ReplacementText: \\2

 

Use Regular Expressions: yes

 

 

If all elements of the list are not empty, there is the 3rd approach. That is, make the first element empty, then concatenate non-empty elements. AttributeCreator: _list{0} <-- <empty> ListConcatenator: Drop Empty Parts = Yes

 

 

Appendix:

 

A concise Python / Tcl script can concatenate list without the first element. PythonCaller

 

-----

 

import fmeobjects def concatenateListWithout1stElement(feature):     delim = ','     src = feature.getAttribute('_list{}')     feature.setAttribute('_concatenated', delim.join(src[1:]) if src else '') -----

 

 

TclCaller

 

-----

 

proc concatenateListWithout1stElement {} {   set delim {,}   set elements {}   for {set i 1} {[FME_AttributeExists "_list{$i}"] == 1} {incr i} {     lappend elements [FME_GetAttribute "_list{$i}"]   }   return [join $elements $delim] }

 

-----

 

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.

1 reply

takashi
Influencer
  • Best Answer
  • November 30, 2013
Hi,

 

 

I would apply Itay's 1st approach with a StringReplacer after concatenating.

 

Assume the separate character is a comma, the StringReplacer parameter settings are:

 

Attributes: _concatenated

 

Text to Find: ^[^,]*(,(.+))?$

 

ReplacementText: \\2

 

Use Regular Expressions: yes

 

 

If all elements of the list are not empty, there is the 3rd approach. That is, make the first element empty, then concatenate non-empty elements. AttributeCreator: _list{0} <-- <empty> ListConcatenator: Drop Empty Parts = Yes

 

 

Appendix:

 

A concise Python / Tcl script can concatenate list without the first element. PythonCaller

 

-----

 

import fmeobjects def concatenateListWithout1stElement(feature):     delim = ','     src = feature.getAttribute('_list{}')     feature.setAttribute('_concatenated', delim.join(src[1:]) if src else '') -----

 

 

TclCaller

 

-----

 

proc concatenateListWithout1stElement {} {   set delim {,}   set elements {}   for {set i 1} {[FME_AttributeExists "_list{$i}"] == 1} {incr i} {     lappend elements [FME_GetAttribute "_list{$i}"]   }   return [join $elements $delim] }

 

-----

 

Takashi

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