<?xml version="1.0" encoding = "utf-8"?>

<snippet xmlns:MMString="http://www.macromedia.com/schemes/dat/string/" MMString:name = "Snippets/JavaScript/string_manipulations/capitalizeWords_csn/snippet/name/Capitalize" MMString:description = "Snippets/JavaScript/string_manipulations/capitalizeWords_csn/snippet/description/Capitalizes" preview="code" type="block">

<insertText location="beforeSelection">

<![CDATA[function capitalizeWords(string)

{

var tmpStr, tmpChar, preString, postString, strlen;

tmpStr = string.toLowerCase();

stringLen = tmpStr.length;

if (stringLen > 0)

{

  for (i = 0; i < stringLen; i++)

  {

    if (i == 0)

	{

      tmpChar = tmpStr.substring(0,1).toUpperCase();

      postString = tmpStr.substring(1,stringLen);

      tmpStr = tmpChar + postString;

    }

    else

	{

      tmpChar = tmpStr.substring(i,i+1);

      if (tmpChar == " " && i < (stringLen-1))

	  {

      tmpChar = tmpStr.substring(i+1,i+2).toUpperCase();

      preString = tmpStr.substring(0,i+1);

      postString = tmpStr.substring(i+2,stringLen);

      tmpStr = preString + tmpChar + postString;

      }

    }

  }

}

return tmpStr;

}]]>

</insertText>

<insertText location="afterSelection"><![CDATA[]]>

</insertText>

</snippet>

