capitalization

How to capitalize the first letter of each word in a string?

僤鯓⒐⒋嵵緔 提交于 2019-11-26 00:31:10
问题 s = \'the brown fox\' ...do something here... s should be : \'The Brown Fox\' What\'s the easiest way to do this? 回答1: The .title() method of a string (either ASCII or Unicode is fine) does this: >>> "hello world".title() 'Hello World' >>> u"hello world".title() u'Hello World' However, look out for strings with embedded apostrophes, as noted in the docs. The algorithm uses a simple language-independent definition of a word as groups of consecutive letters. The definition works in many

How to capitalize the first character of each word in a string

懵懂的女人 提交于 2019-11-25 22:27:44
问题 Is there a function built into Java that capitalizes the first character of each word in a String, and does not affect the others? Examples: jon skeet -> Jon Skeet miles o\'Brien -> Miles O\'Brien (B remains capital, this rules out Title Case) old mcdonald -> Old Mcdonald * *( Old McDonald would be find too, but I don\'t expect it to be THAT smart.) A quick look at the Java String Documentation reveals only toUpperCase() and toLowerCase() , which of course do not provide the desired behavior.

Correct Bash and shell script variable capitalization

二次信任 提交于 2019-11-25 21:59:15
问题 I run across many shell scripts with variables in all caps, and I\'ve always thought that there is a severe misunderstanding with that. My understanding is that, by convention (and perhaps by necessity long ago), environment variables are in all-caps. But in modern scripting environments like Bash, I have always preferred the convention of lower-case names for temporary variables, and upper-case ones only for exported (i.e. environment) variables . For example: #!/usr/bin/env bash year=`date

Capitalize words in string

穿精又带淫゛_ 提交于 2019-11-25 20:39:24
What is the best approach to capitalize words in a string? disfated String.prototype.capitalize = function() { return this.replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); }); }; Usage: 'your string'.capitalize(); // -> 'Your String' fixes Marco Demaio 's solution where first letter with a space preceding is not capitalized. ' javascript'.capitalize(); // -> ' Javascript' can handle national symbols and accented letters. 'бабушка курит трубку'.capitalize(); // -> 'Бабушка Курит Трубку' 'località àtilacol'.capitalize() // -> 'Località Àtilacol' ADD-ON I find it useful String