I have a variable containing some text where I just want to change the first letter to be a capital letter, and leave all the other letters as they are.
I’m struggling to see if there is a function that does that in Wappler or if I need to do something more creative myself.
Any thoughts would be much appreciated as the examples shown in the user interface don’t seem to work…
Try the titlecase formatter, it will make each starting letter from each word uppercase. And if that is not the one you are looking for you could create a custom formatter.
I would have thought you had achieved what you described in the title thread - but I see what you want.
Hopefully @patrick has come up with the best and simplest solution. I was about to suggest a less simple solution, but it might be useful anyway. I've used something like this to do multiple things to the words in a string - using multiple .map()s
Indeed, as I said ("@patrick has come up with the best and simplest solution").
However, it's often useful to know of different solutions to a problem. The solution I suggested did essentially what @Antony asked for - applying formatting to each word in a string. It also offers possibilities than can't be achieved using the built-in formatters. It's a technique I thought @Antony might find useful. It's a technique I learnt from @patrick.
So the actual request is - change only the first letter of a string to capitals, and leave the rest unchanged.
In this case you will need something like:
Additionally, if it’s just for the presentation and you don’t care how it’s stored you can use CSS. This will save you from having to do the transform all over your app if you need it more than once.
i.e.
p.capitalize {
text-transform: capitalize;
}
Edit: Sorry I was too lazy to read all the thread. You just want the first letter of the string. You can use the pseudo-element :first-letter
Hey @teodor and @JonL, thank you sooo much for your replies.
Yes Teodor, what I specifically require is actually the title of the post!
It looks like either of those will work, and since in the actual situation the variable is a more complex {{server_action.data.query.field_name}} I think I’ll go for the CSS.
I fixed the title for you. You didn't mention in it the word "string/sentence/paragraph/group of words". It was an important detail
That's why my first CSS solution was in line with the others. I had to read the entire thread to understand you were referring to a string.