First capital letter.

Is there a way to make the first letter in the text Uppercase and the others lowercase?

I am trying to use:

("weatherCondition").toString().toUpper()); ,but it doesn't work for me.

Thanks

  • As you've found, your code makes all the characters in the string uppercase, not just the first one.

    Use String.substring() to split the input into 2 pieces (1st letter and the remaining letters). Use toUpper() on the first piece, use toLower() on the second piece, and return the concatenation of the two resulting pieces.

    function titleCase(str as String) as String {
      return str.substring(0, 1).toUpper() + str.substring(1, str.length()).toLower();
    }

  • Thank you very much, but I would need to embed it here:

     dc.setColor(Graphics.COLOR_BLACK, Graphics.COLOR_TRANSPARENT);
     dc.drawText(x, y, $.Font_decc, textWeatherDesc, Graphics.TEXT_JUSTIFY_CENTER);

    and I can't do that.

  • dc.drawText(x, y, $.Font_decc, titleCase(textWeatherDesc), Graphics.TEXT_JUSTIFY_CENTER);

  • Thank you very much...Mortar board