13

Is there a convenient way to transform a string that is all lower case so that the first character is upper case?

I currently have a working solution:

#PROTO_NAME is the lower-case string
string(SUBSTRING ${PROTO_NAME} 0 1 FIRST_LETTER)
string(TOUPPER ${FIRST_LETTER} FIRST_LETTER)
string(REGEX REPLACE "^.(.*)" "${FIRST_LETTER}\\1" PROTO_NAME_CAP "${PROTO_NAME}")

The result is in the PROTO_NAME_CAP variable. Is there a simpler or more convenient way to achieve this?

Anthony
  • 12,177
  • 9
  • 69
  • 105

1 Answers1

11

There is no built-in solution for this in CMake. You can only hide your code behind a function if you want to make things more readable.

languitar
  • 6,554
  • 2
  • 37
  • 62