Tinderbox Forum

How to change only the first letter of a string to lower case

I would like to make lowercase the first character of a string, leaving untouched the rest of the string. It seems to me that this task cannot be achieved with the String.lowercase() function. I have also tried to use a regular expression pattern, but \L (convert to lower case) and \E (turn off case conversion) don’t seem to work in Tinderbox. Therefore, I cannot achieve this task with:

$Name = $Name.replace("^([A-ZÀ-Ÿ])(.*)","\L$1\E$2");

Thank you in advance for any help.

What about something like:


One suggested tweak


Thank you, Mark and Paul. I had overlooked the substr function.

Let me point out that such function works for unaccented capital letters, but it misbehaves with the accented capital letters used in Spanish, such as in the word Álgebra.

As this seems to be an internal problem of Tinderbox that could be corrected, let me explain that in Spanish it is Á É Í Ó Ú that would need to be covered, but there are more accents types in other languages. In regex I believe they are contained in [À-ÿ].

Confirmed. The suggested code, above, results in a variety of weird outcomes when the initial character in a string, or other characters in the string, have diacritics.

Using this, it works fine for unaccented text but is the first character is a capital accented character I get a crash (logs emailed).

This might be something to do with it:

I’ve a hunch .lowercase() (and .uppercase()?) might not be fully Unicode compatible, in terms of case translation for non-ASCII roman characters.

1 Like

I had no crashes, but using this $Name=$Name.substr(0,1).lowercase+$Name.substr(1); as stamp on notes whose $Name begins with a character with a diacritic caused $Name to vanish.

Then I take it I don’t have to report this issue to @eastgate. I hope it gets resolved in a coming Tinderbox version.

Thank you again to both of you for your follow up.

Yes I think this can be regarded as reported. I’ve sent in crash logs with a link to this thread.

1 Like