Capitalize the first letter of sentense in JavaScript/Jquery

This question already has an answer here:

  • How do I make the first letter of a string uppercase in JavaScript? 69 answers

  • You don't need jQuery for this. You can use Javascript string and array functions.

  • Split the string by . , to separate different sentences
  • Trim each sentence
  • Capitalize first letter
  • Join by .
  • var str = 'this is a test. this is one more test. and this also new test.';
    
    var newStr = str.split('.').map(function(el) {
      el = el.trim();
      return el.substr(0, 1).toUpperCase() + el.substr(1);
    }).join('. ');
    
    alert(newStr.trim());
    链接地址: http://www.djcxy.com/p/17864.html

    上一篇: 在json发送时大写首字母的字符串

    下一篇: 在JavaScript / Jquery中使用首字母大写