Title Case

Results 1 to 3 of 3

Thread: Title Case

  1. #1
    Join Date
    Dec 1969

    Default Title Case

    The following code works very well. I do have one modification that I&#039;m struggling with. I want to split by spaces and cap each word based on that split (being done currently). But, there are times when I&#039;ll have a "slash" separating words (or for that matter, any number of non-alpha/non-numeric characters). I also want to cap the word immediately following the non-alpha/non-numeric characters (I say plural because that is a distinct possibility). Any thoughts on how to accomplish? Thanks!<BR><BR>&#060;script lanugage="javascript"&#062;<BR>&#060;!-- BEGIN<BR>function titleCase(sValue) {<BR> sValue = sValue.toLowerCase()<BR> var sReturn = &#039;&#039;;<BR> var sWord = &#039;&#039;;<BR> var sParts = sValue.split(" ");<BR><BR> for (i = 0; i &#060; sParts.length; i++){<BR> if (i &#062; 0) {<BR> sReturn += &#039; &#039;;<BR> }<BR> if (sParts[i].length &#062; 0) {<BR> sWord = sParts[i].substr(0);<BR> sReturn += sParts[i].charAt(0).toUpperCase() + sParts[i].substr(1);<BR> }<BR> }<BR> return sReturn; <BR>}<BR>// - END --&#062;<BR>&#060;/script&#062;

  2. #2
    Join Date
    Dec 1969

    Default RE: Title Case .. Usually called Proper Case

    Just have to check for more conditions after you split on the " " I guess. The more conditions you want to handle the longer your code will be. If you want to search and see if anyone else has done what you want do a search on "Proper Case"

  3. #3
    Join Date
    Dec 1969
    Los Angeles, CA

    Default Yep

    you have to add code for every "thingie" you want to "caps" after<BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts