»
AnglaisFrançaisVietnamien

Imprimer - Conversion d'une chaîne de Titre/Peine de cas - JavaScriptBank.com

Version complète: jsB@nk » Form » Conversion d'une chaîne de Titre/Peine de cas
URL: https://www.javascriptbank.com/converting-a-string-to-title-sentence-case.html

Conversion d'une chaîne de Titre/Peine de cas © JavaScriptBank.comCet JavaScript vous permet de convertir un ensemble de mots à la peine de cas ou titre cas. Ugly mais rapide JavaScript pour convertir une phrase titre cas.

Version complète: jsB@nk » Form » Conversion d'une chaîne de Titre/Peine de cas
URL: https://www.javascriptbank.com/converting-a-string-to-title-sentence-case.html



JavaScript
<SCRIPT language=javascript>function rtrim(strInput) {  while (1) {    if (strInput.substring(strInput.length - 1, strInput.length) != " ")      break;    strInput = strInput.substring(0, strInput.length - 1);  }  return strInput;}function ltrim(strInput) {  while (1) {    if (strInput.substring(0, 1) != " ")      break;    strInput = strInput.substring(1, strInput.length);  }  return strInput;}function trim(strInput) {  var tmpstr = ltrim(strInput);  return rtrim(tmpstr);}function sentencecase(strInput){strInput = trim(strInput);strInput = ' ' + strInput;strInput=strInput.toLowerCase();var firstcharlc=strInput.charAt(1);var firstcharuc=firstcharlc.toUpperCase();firstcharuc = " " + firstcharuc;firstcharlc = " " + firstcharlc;strInput=strInput.replace(firstcharlc, firstcharuc);strInput=trim(strInput);var len = strInput.length;var spacePos = strInput.indexOf(' ');while (spacePos != -1) {var firstcharlc = strInput.charAt(spacePos+1);var firstcharuc=firstcharlc.toUpperCase();firstcharuc = " " + firstcharuc;firstcharlc = " " + firstcharlc;strInput=strInput.replace(firstcharlc, firstcharuc);strInput=trim(strInput);spacePos = strInput.indexOf(' ',spacePos+1);}return strInput;}</SCRIPT><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<FORM name=MYFORM><INPUT name=mySentence> <INPUT onclick="document.MYFORM.mySentence.value = sentencecase(document.MYFORM.mySentence.value);" type=button value="Click Here"> </FORM><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->