python capitalize first letter only

Only because no one else has mentioned it: >>> ‘bob’.title() ‘Bob’ >>> ‘sandy’.title() ‘Sandy’ >>> ‘1bob’.title() ‘1Bob’ >>> ‘1sandy’.title() ‘1Sandy’ However, this would also give >>> ‘1bob sandy’.title() ‘1Bob Sandy’ >>> ‘1JoeBob’.title() ‘1Joebob’ i.e. it doesn’t just capitalize the first alphabetic character. But then .capitalize() has the same issue, at least in that ‘joe Bob’.capitalize() … Read more

How do I capitalize first letter of first name and last name in C#?

TextInfo.ToTitleCase() capitalizes the first character in each token of a string. If there is no need to maintain Acronym Uppercasing, then you should include ToLower(). string s = “JOHN DOE”; s = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(s.ToLower()); // Produces “John Doe” If CurrentCulture is unavailable, use: string s = “JOHN DOE”; s = new System.Globalization.CultureInfo(“en-US”, false).TextInfo.ToTitleCase(s.ToLower()); See the MSDN … Read more

Regex capitalize first letter every word, also after a special character like a dash

+1 for word boundaries, and here is a comparable Javascript solution. This accounts for possessives, as well: var re = /(\b[a-z](?!\s))/g; var s = “fort collins, croton-on-hudson, harper’s ferry, coeur d’alene, o’fallon”; s = s.replace(re, function(x){return x.toUpperCase();}); console.log(s); // “Fort Collins, Croton-On-Hudson, Harper’s Ferry, Coeur D’Alene, O’Fallon”

Capitalize first letter. MySQL

It’s almost the same, you just have to change to use the CONCAT() function instead of the + operator : UPDATE tb_Company SET CompanyIndustry = CONCAT(UCASE(LEFT(CompanyIndustry, 1)), SUBSTRING(CompanyIndustry, 2)); This would turn hello to Hello, wOrLd to WOrLd, BLABLA to BLABLA, etc. If you want to upper-case the first letter and lower-case the other, you … Read more

How to autocapitalize the first character in an input field in AngularJS?

Yes, you need to define a directive and define your own parser function: myApp.directive(‘capitalizeFirst’, function($parse) { return { require: ‘ngModel’, link: function(scope, element, attrs, modelCtrl) { var capitalize = function(inputValue) { if (inputValue === undefined) { inputValue=””; } var capitalized = inputValue.charAt(0).toUpperCase() + inputValue.substring(1); if(capitalized !== inputValue) { modelCtrl.$setViewValue(capitalized); modelCtrl.$render(); } return capitalized; } modelCtrl.$parsers.push(capitalize); … Read more

How to capitalize the first letter of a String in Java?

String str = “java”; String cap = str.substring(0, 1).toUpperCase() + str.substring(1); // cap = “Java” With your example: public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // Actually use the Reader String name = br.readLine(); // Don’t mistake String object with a Character object String s1 = name.substring(0, 1).toUpperCase(); … Read more

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

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 … Read more