Quicktip - Capitalizing text

Hey all,

I think you'll find this little tip handy.

Text Blaze has in-built functions for changing the case of a string of text to:

  • all uppercase
  • all lowercase
  • title case (capitalizing the first letter of every word)

Here's how it's done:

{formtext: name=text; default=the QUICK BrowN fOx juMPed Over the LAZY doGs}

No change: {=text}
All uppercase: {=upper(text)}
All lowercase: {=lower(text)}
Title case: {=proper(text)}

If you want to change the text to sentence case (only the first letter of the first word in the sentence is capitalized) you can do it this way:

{formtext: name=text; default=the QUICK BrowN fOx juMPed Over the LAZY doGs}

{=replaceregex(lower(text), ".", upper(extractregex(text, ".")))}

4 Likes

Thank you for sharing

2 Likes

Hi Cedric! If I wanted to have a text field from a website be all proper case, how would I format that? The selector is {site: text; selector=.PropertyInfoSummary__ldpLink}. Thank you!

@log62000 you can put that site command inside of the UPPER function, or the PROPER function, depending on what you mean exactly. This preview won't work in the community since the site selector won't find any match, but this shows exactly how you'd want to format it:

To make ALL THE TEXT UPPERCASE: {=upper({site: text; selector=.PropertyInfoSummary__ldpLink})}

To make The First Letter Of Each Word Capitalized: {=proper({site: text; selector=.PropertyInfoSummary__ldpLink})}

Thank you so much Andrew! That's perfect!!

It's a bit picky, but Title Case doesn't capitalize all words. I'm not sure it could accomodate the rules? I'd be interested to explore this if you think it is possible.

Hi @Justin_Heath,

You can write a lambda function for the required behaviour like this:

{title_case=(sentence)->join(map(split(lower(sentence), " "), (word,i)->word if i<>1 and i<>count(split(sentence," ")) and includes(["a", "an", "the", "and", "but", "for", "at", "by", "in", "to", "of", "on", "or", "nor", "so", "yet", "up", "off", "out", "over", "with"], word) else proper(word)), " ")}{=title_case("the catcher in the rye")}

2 Likes

I didn't know that was possible in TB. Looks really promising. For some reason, I get this output:

The Catcher in theThe Catcher in the Rye

It seems like you are using both the Text Blaze extension and the Windows/macOS app, which is causing the snippet to trigger both simultaneously. To avoid this, you can change the setting by going to the "Options" menu and changing the "Windows/macOS app in Chrome-based browsers (like Chrome and Brave)” setting.

Screenshot 2023-10-25 at 5.37.12 PM

Screenshot 2024-01-18 at 6.34.12 PM

1 Like

Thanks, that's sorted it out.

Also, I've altered the snippet ever so slightly to work on the clipboard contents. It's exactly what I was looking for and will save a lot of time. Thanks for your help.

{=title_case({clipboard})}

2 Likes

Hi again, I'm trying to complete my toolkit, by adapting the title case to handle camel case, but I'm not expert in TB script yet, so having trouble.

If it's OK, can you let me know where have I gone wrong with this?

{camel_case=(sentence)->join(map(split(sentence, " "), (word) -> upper(slice(word, 1, 2)) + lower(slice(word, 2))), "")}
{=camel_case("one two three four five")}

Hi @Justin_Heath,

I think the issue is happening as word is a string so you should use substring instead of slice. Also to concatenate two strings you should use & instead of +.

{camel_case=(sentence)->join(map(split(sentence, " "), (word) -> upper(substring(word, 1, 1)) & lower(substring(word, 2))), " ")}
{=camel_case("one two three four five")}

1 Like

Thank you. I can see that. Finally, is there a way to select the first word and not capitalise within this, or would that need a regex replacement to follow?

Yes, actually, the map function provides two arguments one will be a word and the other will be its index from 1 (first word) to the number of words in the sentence (last word) so you can do like this:

{camel_case=(sentence)->join(map(split(sentence, " "), (word, i) -> upper(substring(word, 1, 1)) & lower(substring(word, 2)) if i<>1 else word), " ")}
{=camel_case("one two three four five")}

1 Like

I see now. Thank you! I'm getting used to TB after a long time using TE. I'm liking it much more.

4 Likes