Skip to main content
Question

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

  • March 7, 2018
  • 7 replies
  • 749 views

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

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, 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.

7 replies

takashi
Celebrity
  • 7843 replies
  • 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
Safer
Forum|alt.badge.img+20
  • Safer
  • 3719 replies
  • March 7, 2018

Hi @edhere Or with a TclCaller:

return [string toupper [FME_GetAttribute _text] 0 0]

Forum|alt.badge.img
  • Author
  • 60 replies
  • 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
Celebrity
  • 7843 replies
  • March 7, 2018

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))) 

denizturan1985
Participant
Forum|alt.badge.img
  • Participant
  • 11 replies
  • 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?

 

Hi Ed, I think it should be like:

takashi
Celebrity
  • 7843 replies
  • 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?

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
Celebrity
  • 7843 replies
  • 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?

If you are interested in Tcl, try this.

 

0684Q00000ArMKnQAN.png