Capitalize first letters only
Is there some function / method to capitalize only the first letter of each word in a text field?
I looked at
upper() for a possible optional parameter to do this but no.
I also looked at
printf but didn't see a relevant format.
Any other way? Perhaps, a loadable extension someone has written and willing to share?
(2.1) By Gunter Hick (gunter_hick) on 2020-08-05 15:02:27 edited from 2.0 in reply to 1 [source]
That kind of operation is best done at application level. SQL does not lend itself well to string manipulation. The requested operation is a one-liner in Perl for example.
If by some cosmic accident you want this as a once-off DB operation or you happen to use SQLiteSpeed for a DB manager, then there is an SQL function called "TitleCase()" that you can use which will render:
- TitleCase('JOHNNY') --> 'Johnny'
- TitleCase('john smith') --> 'John Smith'
- TitleCase('jOhNnY b. GOODE') --> 'Johnny B. Goode'
- TitleCase('my name') --> 'My Name'
Failing that, the best option is to add such a UDF to the SQLite library that you are using as explained here.
Note some base peculiarities with the above function (or things to consider if you are making your own) that may or may not be desired:
- TitleCase('joe McAdam') --> 'Joe Mcadam'
- TitleCase('Mary-joe smith') --> 'Mary-Joe Smith'
- TitleCase('JK. Rowling') --> 'Jk. Rowling'
Other than that, as Gunther mentioned, best to do it inside your application code.
Thanks for the SQLitespeed pointer. Yes, that was a one-off job (for now).
Unfortunately, the app has too many issues to replace my other browser (sqlitebrowser), like throwing errors when there should't be any (even after updating its sqlite3.dll with mine to be one same page), or not updating the view after running an
But, I somehow managed to complete the job eventually. So, thanks.