capitalize

Capitalize First Letter Of Each Word In A String - JavaScript

岁酱吖の 提交于 2019-11-26 06:35:03
问题 What is wrong with this function? I am lost thanks for help. function titleCase(str) { var splitStr = str.toLowerCase().split(\' \'); for (var i = 0; i < splitStr.length; i++) { if (splitStr.length[i] < splitStr.length) { splitStr[i].charAt(0).toUpperCase(); } str = splitStr.join(\' \'); } return str; } titleCase(\"I\'m a little tea pot\"); 回答1: You are not assigning your changes to the array again, so all your efforts are in vain. Try this: function titleCase(str) { var splitStr = str

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

耗尽温柔 提交于 2019-11-26 06:18:58
问题 How to autocapitalize the first character in an input field inside an AngularJS form element? I saw the jQuery solution already, but believe this has to be done differently in AngularJS by using a directive. 回答1: 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) {

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 do I make the first letter of a string uppercase in JavaScript?

隐身守侯 提交于 2019-11-25 23:56:31
问题 How do I make the first letter of a string uppercase, but not change the case of any of the other letters? For example: \"this is a test\" -> \"This is a test\" \"the Eiffel Tower\" -> \"The Eiffel Tower\" \"/index.html\" -> \"/index.html\" 回答1: function capitalizeFirstLetter(string) { return string.charAt(0).toUpperCase() + string.slice(1); } Some other answers modify String.prototype (this answer used to as well), but I would advise against this now due to maintainability (hard to find out