javascript - jQuery or PHP capitalise string and concatenate in one function -


i had separated out , long function, take 3 different words, capitalise first letter , store them in new variable, concatenated.

instead trying find solution code can minimised , doesn't have have different function concatenation, capitalisation etc.

how this? 3 strings wordchoiceonce, wordchoicetwo , wordchoicethree

so need (pseudo-code):

function saveusername(wordchoiceonce, wordchoicetwo, wordchoicethree){      // capitalise first letter of words      // concatenate words in order      //store words in var username; } 

edit: after have stored var, planned pass php variable. maybe easier offer php solution instead? , pass each word php, capitalise , concat.

php has ucwords, has been ported javascript. so, well-known function gets this:

function saveusername(wordchoiceonce, wordchoicetwo, wordchoicethree){     function ucwords(str) {       //  discuss at: http://phpjs.org/functions/ucwords/       // original by: jonas raoni soares silva (http://www.jsfromhell.com)       // improved by: waldo malqui silva       // improved by: robin       // improved by: kevin van zonneveld (http://kevin.vanzonneveld.net)       // bugfixed by: onno marsman       //    input by: james (http://www.james-bell.co.uk/)       //   example 1: ucwords('kevin van  zonneveld');       //   returns 1: 'kevin van  zonneveld'       //   example 2: ucwords('hello world');       //   returns 2: 'hello world'        return (str + '')         .replace(/^([a-z\u00e0-\u00fc])|\s+([a-z\u00e0-\u00fc])/g, function($1) {           return $1.touppercase();         });     }      return ucwords(wordchoice1) + ' ' + ucwords(wordchoicetwo) + ' ' + ucwords(wordchoicethree); } 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -