Skip to main content
Question

How to capitalize first letter in string and leave the rest of string as is?


Forum|alt.badge.img

Hello,

I'm looking for a way to capitalize the first letter of a string but leave the rest of the string untouched.

 

I have tried the StringCaseChanger, but that didn't seem to yield the result I was looking for. Have Want de Gouden Draak De Gouden Draak het Rijksmuseum Het Rijksmuseum paleis op de Dam Paleis op de Dam

Thanks,

Ed

7 replies

takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • March 7, 2018

Hi @edhere, split the input string into the first character and the rest part, change the first character to uppercase, then concatenate them. The SubstringExtractor, the StringCaseChanger, and the StringConcatenator might help you.

Alternatively this string expression could also work as well.

@UpperCase(@Substring(@Value(_text),0,1))@Substring(@Value(_text),1)

fmelizard
Contributor
Forum|alt.badge.img+17
  • Contributor
  • March 7, 2018

Hi @edhere Or with a TclCaller:

return [string toupper [FME_GetAttribute _text] 0 0]

Forum|alt.badge.img
  • Author
  • March 7, 2018

Hi guys,

Thanks for the comments, I couldn't get above solutions to work so I used below. Seems to do the trick as well.

0684Q00000ArL97QAF.jpg

But a shorter version would be nice of course!

@takashi - Where would I put:

@UpperCase(@Substring(@Value(_text),0,1))@Substring(@Value(_text),1)

In an AttributeManager?

@DanAtSafe - I'm not familiar with the TclCaller, can you perhaps show me how the transformer should look with the code?


takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • March 7, 2018
fmelizard wrote:

Hi @edhere Or with a TclCaller:

return [string toupper [FME_GetAttribute _text] 0 0]
Scripting. I tried other languages, but probably the Tcl expression could be most concise.

 

JavaScript (JavaScriptCaller)

 

var t = fme_get_attribute('_text');
fme_set_attribute('_result', t.replace(/^./, t.charAt(0).toUpperCase()));
XQuery (XMLXQueryExtractor)

 

let $t := fme:get-attribute("_text")
return fn:replace($t'^.', fn:upper-case(fn:substring($t,1,1))) 

Forum|alt.badge.img
edhere wrote:

Hi guys,

Thanks for the comments, I couldn't get above solutions to work so I used below. Seems to do the trick as well.

0684Q00000ArL97QAF.jpg

But a shorter version would be nice of course!

@takashi - Where would I put:

@UpperCase(@Substring(@Value(_text),0,1))@Substring(@Value(_text),1)

In an AttributeManager?

@DanAtSafe - I'm not familiar with the TclCaller, can you perhaps show me how the transformer should look with the code?

 

Hi Ed, I think it should be like:

takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • March 7, 2018
edhere wrote:

Hi guys,

Thanks for the comments, I couldn't get above solutions to work so I used below. Seems to do the trick as well.

0684Q00000ArL97QAF.jpg

But a shorter version would be nice of course!

@takashi - Where would I put:

@UpperCase(@Substring(@Value(_text),0,1))@Substring(@Value(_text),1)

In an AttributeManager?

@DanAtSafe - I'm not familiar with the TclCaller, can you perhaps show me how the transformer should look with the code?

The string expression is just an alternative. You can set the expression to the Attribute Value column in an AttributeManager or AttributeCreator.

 

0684Q00000ArMc8QAF.png

However, if you got your desired result from those transformers, no need to use the expression.

takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • March 7, 2018
edhere wrote:

Hi guys,

Thanks for the comments, I couldn't get above solutions to work so I used below. Seems to do the trick as well.

0684Q00000ArL97QAF.jpg

But a shorter version would be nice of course!

@takashi - Where would I put:

@UpperCase(@Substring(@Value(_text),0,1))@Substring(@Value(_text),1)

In an AttributeManager?

@DanAtSafe - I'm not familiar with the TclCaller, can you perhaps show me how the transformer should look with the code?

If you are interested in Tcl, try this.

 

0684Q00000ArMKnQAN.png

 


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