Skip to main content

FME 2017.0.0.0

I try to use StringReplacer to uppercase letters to lowercase letters, but failed.

 

Attribute:attr (has a value "ABCD")

 

Mode:Realace Regular Expression

 

Text To Replace:(>A-Z])

 

Replacement Text:@LowerCase(\\1)

I also tried the @UpperCase,@Format,@PadLeft,@PadRight..., but those function seems does not work for regular expression groups (\\1) too.

String functions cannot be used in a regular expression group?

Hi @taojunabc, why not use the StringCaseChanger, or am I missing something?


Hi @itay,

Sorry,
I did not describe the problem clearly, My ultimate goal is to handle the list attributes, such as attribute{}.name. But StringCaseChanger can not be applied to the list attributes.

Please refer to the link below?

Lowercase PostGIS table names

In FME hub, there is a custom transformer called ListStringReplacer, It
is possible to use regular expressions, but I tried it and found that
it has the same behavior as StringReplacer, in order to simplify the
problem, I mentioned only StringReplacer.


Hi @taojunabc, I don't know if it's intentional that FME String Functions do not work for the resulting string from the StringReplacer. I remember that there was the same question before, but was not able to find out that.

Scripting may be a quick workaround in your case.

PythonCaller Script Example:

def toLower(feature):
    names = feature.getAttribute('attribute{}.name')
    if names:
        for i, s in enumerate(names):
            feature.setAttribute('attribute{%d}.name' % i, s.lower())

TclCaller Script Example:

proc toLower {} {
    for {set i 0} {1} {incr i} {
        set attr "attribute{$i}.name"
        if {!ÂFME_AttributeExists $attr]} {
            break
        }
        FME_SetAttribute $attr  string tolower !FME_GetAttribute $attr]]
    }
}

Hi @itay,

Sorry,
I did not describe the problem clearly, My ultimate goal is to handle the list attributes, such as attribute{}.name. But StringCaseChanger can not be applied to the list attributes.

Please refer to the link below?

Lowercase PostGIS table names

In FME hub, there is a custom transformer called ListStringReplacer, It
is possible to use regular expressions, but I tried it and found that
it has the same behavior as StringReplacer, in order to simplify the
problem, I mentioned only StringReplacer.

I see, this makes sense, beside the elegant solution by @takashi the only other way I can think of is by exploding the list and applying the case change.

 


Hi @taojunabc, I don't know if it's intentional that FME String Functions do not work for the resulting string from the StringReplacer. I remember that there was the same question before, but was not able to find out that.

Scripting may be a quick workaround in your case.

PythonCaller Script Example:

def toLower(feature):
    names = feature.getAttribute('attribute{}.name')
    if names:
        for i, s in enumerate(names):
            feature.setAttribute('attribute{%d}.name' % i, s.lower())

TclCaller Script Example:

proc toLower {} {
    for {set i 0} {1} {incr i} {
        set attr "attribute{$i}.name"
        if {!ÂFME_AttributeExists $attr]} {
            break
        }
        FME_SetAttribute $attr  string tolower !FME_GetAttribute $attr]]
    }
}
Thank you for providing sample code,  PythonCaller or TclCaller is a relatively simple solution. 

 

 


I see, this makes sense, beside the elegant solution by @takashi the only other way I can think of is by exploding the list and applying the case change.

 

Hi @itay,Thanks.

 

I did not think of other solution, the solution by @takashi is very simple, I decided to use his solution.

 


Reply