Tinderbox Forum

Make first character in a $Text lowercase

If I wanted the make the first character in $Text lowercase and save the case for everything else the same, how would I go about doing that?


First: why would you want to do this? (I’m sure there’s a good reason! But future readers will prefer to read about the good reason!)

You can get the first character of text from $Text.substring(0,1). So the lowercase is $Text.substring(0,1).lowercase.

The rest of the substring is $Text.substring(1).

So, I believe you want $Text.substring(0,1).lowercase+$Text.substring(1)

I’ll also be interested to hear the use case, but I can sort of see one. Take a mixed case term like ‘aTbRef’ and formatting it correctly if fed the wrong casing. As it is, I’d use @eastgate’s method as above, though at some point substring becomes the operator to substr in current action code so:


Indeed, now we have functions, we could parameterise which character(s) are to be altered and to which upper/lower case state. I say that as if a String.makeFirstLetterUppercase() were added, doubtless it would lead to someone needing to change the fifth character to lowercase, etc. I don’t think there even a one-function-fits-all as I think there are two slightly different but similar patterns here:

  • very fixed, we’re essentially fixing a known mixed-case string.
  • using a pattern, e.g. changing the case of every Nth character, or some such.

If you’re going to @satikusala’s process a lot, i.e. in many different codes in a doc, then we could wrap @eastgate’s code like so:

function changeLetterAtN(iString,iN){
   var:string vStr = iString;
   var:number vN;
   return  vStr.substr(0,vN).lowercase+$Text.substr(vN);

But what if N isn’t one? The above could be adapted. Indeed what if N was several positions in-string and/or iString was actually a list of strings to be altered ad the same positions. I think a function could do this but I’ve not time to go actually make these functions ATM.

Thanks, i’ll circle back and explain, once I get it working.

1 Like

Here is the explanation of what I wanted to do.

I have note with text:

I want to use this text in different contexts, e.g. as a standalone note where the first character is capitalized and inline in the text where it is lowercase.

**Standalone note example: **

**Table note example, the first character needs to be lower case. **

Here is the template I’ve used to address this:

The action sets the first character to lower case and resets it to upper case at the end.

All is working now.

1 Like