title-case

How can I capitalize the first letter of each word in a string in Perl?

故事扮演 提交于 2019-11-29 05:27:42
What is the easiest way to capitalize the first letter in each word of a string? piCookie See the faq . I don't believe ucfirst() satisfies the OP's question to capitalize the first letter of each word in a string without splitting the string and joining it later. Pat As @brian is mentioning in the comments the currently accepted answer by @piCookie is wrong! $_="what's the wrong answer?"; s/\b(\w)/\U$1/g print; This will print "What'S The Wrong Answer?" notice the wrongly capitalized S As the FAQ says you are probably better off using s/([\w']+)/\u\L$1/g or Text::Autoformat Take a look at the

Titlecasing a string with exceptions

时光怂恿深爱的人放手 提交于 2019-11-27 11:24:23
Is there a standard way in Python to titlecase a string (i.e. words start with uppercase characters, all remaining cased characters have lowercase) but leaving articles like and , in , and of lowercased? There are a few problems with this. If you use split and join, some white space characters will be ignored. The built-in capitalize and title methods do not ignore white space. >>> 'There is a way'.title() 'There Is A Way' If a sentence starts with an article, you do not want the first word of a title in lowercase. Keeping these in mind: import re def title_except(s, exceptions): word_list =

Is there a simple way to convert MySQL data into Title Case?

ⅰ亾dé卋堺 提交于 2019-11-26 20:03:20
I have a MySQL table where all the data in one column was entered in UPPERCASE, but I need to convert in to Title Case, with recognition of "small words" akin to the Daring Fireball Title Case script . I found this excellent solution for transforming strings to lowercase, but the Title Case function seems to have been left out of my version of MySQL. Is there an elegant way to do this? hobodave Edit Eureka! Literally my first SQL function. No warranty offered. Back up your data before using. :) First, define the following function: DROP FUNCTION IF EXISTS lowerword; SET GLOBAL log_bin_trust

String conversion to Title Case

守給你的承諾、 提交于 2019-11-26 17:32:37
Is there any built in methods available to convert a string into Title Case format as such? aberrant80 Apache Commons StringUtils.capitalize() or WordUtils.capitalize() e.g: WordUtils.capitalize("i am FINE") = "I Am FINE" from WordUtils doc there are no capitalize() or titleCase() methods in String class. You have two choices: using commons lang string utils . StringUtils.capitalize(null) = null StringUtils.capitalize("") = "" StringUtils.capitalize("cat") = "Cat" StringUtils.capitalize("cAt") = "CAt" StringUtils.capitalize("'cat'") = "'cat'" write (yet another) static helper method

RegEx to split camelCase or TitleCase (advanced)

大城市里の小女人 提交于 2019-11-26 11:43:06
I found a brilliant RegEx to extract the part of a camelCase or TitleCase expression. (?<!^)(?=[A-Z]) It works as expected: value -> value camelValue -> camel / Value TitleValue -> Title / Value For example with Java: String s = "loremIpsum"; words = s.split("(?<!^)(?=[A-Z])"); //words equals words = new String[]{"lorem","Ipsum"} My problem is that it does not work in some cases: Case 1: VALUE -> V / A / L / U / E Case 2: eclipseRCPExt -> eclipse / R / C / P / Ext To my mind, the result shoud be: Case 1: VALUE Case 2: eclipse / RCP / Ext In other words, given n uppercase chars: if the n chars

Capitalize the first letter of both words in a two word string

邮差的信 提交于 2019-11-26 06:39:27
Let's say that I have a two word string and I want to capitalize both of them. name <- c("zip code", "state", "final count") The Hmisc package has a function capitalize which capitalized the first word, but I'm not sure how to get the second word capitalized. The help page for capitalize doesn't suggest that it can perform that task. library(Hmisc) capitalize(name) # [1] "Zip code" "State" "Final count" I want to get: c("Zip Code", "State", "Final Count") What about three-word strings: name2 <- c("I like pizza") The base R function to perform capitalization is toupper(x) . From the help file

RegEx to split camelCase or TitleCase (advanced)

橙三吉。 提交于 2019-11-26 05:50:33
问题 I found a brilliant RegEx to extract the part of a camelCase or TitleCase expression. (?<!^)(?=[A-Z]) It works as expected: value -> value camelValue -> camel / Value TitleValue -> Title / Value For example with Java: String s = \"loremIpsum\"; words = s.split(\"(?<!^)(?=[A-Z])\"); //words equals words = new String[]{\"lorem\",\"Ipsum\"} My problem is that it does not work in some cases: Case 1: VALUE -> V / A / L / U / E Case 2: eclipseRCPExt -> eclipse / R / C / P / Ext To my mind, the

String conversion to Title Case

青春壹個敷衍的年華 提交于 2019-11-26 04:44:54
问题 Is there any built in methods available to convert a string into Title Case format as such? 回答1: Apache Commons StringUtils.capitalize() or WordUtils.capitalize() e.g: WordUtils.capitalize("i am FINE") = "I Am FINE" from WordUtils doc 回答2: there are no capitalize() or titleCase() methods in String class. You have two choices: using commons lang string utils. StringUtils.capitalize(null) = null StringUtils.capitalize("") = "" StringUtils.capitalize("cat") = "Cat" StringUtils.capitalize("cAt")

SQL Server: Make all UPPER case to Proper Case/Title Case

馋奶兔 提交于 2019-11-26 03:07:21
问题 I have a table that was imported as all UPPER CASE and I would like to turn it into Proper Case. What script have any of you used to complete this? 回答1: Here's a UDF that will do the trick... create function ProperCase(@Text as varchar(8000)) returns varchar(8000) as begin declare @Reset bit; declare @Ret varchar(8000); declare @i int; declare @c char(1); if @Text is null return null; select @Reset = 1, @i = 1, @Ret = ''; while (@i <= len(@Text)) select @c = substring(@Text, @i, 1), @Ret =

Convert string to title case with JavaScript

佐手、 提交于 2019-11-25 21:44:33
问题 Is there a simple way to convert a string to title case? E.g. john smith becomes John Smith . I\'m not looking for something complicated like John Resig\'s solution, just (hopefully) some kind of one- or two-liner. 回答1: Try this: function toTitleCase(str) { return str.replace( /\w\S*/g, function(txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); } ); } <form> Input: <br /><textarea name="input" onchange="form.output.value=toTitleCase(this.value)" onkeyup="form.output