Better replacement for strings.Title?

435 views
Skip to first unread message

Kevin Chowski

unread,
Mar 30, 2022, 11:59:24 AM3/30/22
to golang-nuts
strings.Title is newly deprecated, but unfortunately the suggested replacement (golang.org/x/text/cases) doesn't seem to be equivalent for my usecase. At least, I can't figure out how to make it equivalent :)

Specifically, I wrote some code that relies on converting a string like "myInput" into "MyInput", which is what strings.Title does. Unfortunately, the cases package seems to turn it into "Myinput": https://go.dev/play/p/yucD99ytNK7 . I've tried a few different language.Tag values but nothing seems to work the way I need it to work.

Will I have to just keep using this old version, or is there a way to get the new library working the way I need it to work?

Thanks again in advance for the advice,
Kevin

Kevin Chowski

unread,
Mar 30, 2022, 12:15:40 PM3/30/22
to golang-nuts
I guess "Better" is not really what I mean... maybe more accurately I need something "closer" to strings.Title.

Kevin Chowski

unread,
Mar 30, 2022, 12:19:08 PM3/30/22
to golang-nuts
Someone replied off-list and suggested using the cases.NoLower option while initializing the Caser. And it worked! Thanks!
Reply all
Reply to author
Forward
0 new messages