0

this is a test. this is one more test. and this also new test.

This is test. This is one more test. And this is new test.

Tushar
  • 85,780
  • 21
  • 159
  • 179
Dipen Soni
  • 41
  • 3
  • 1
    @Satpal This is not the exact duplicate, however that can help to solve this problem – Tushar Jul 22 '15 at 06:30
  • Like @Tushar says. The link don't answer the question. And according to the tags I would like an answer in vanilla Js. This question is a bit poorly formatted thou. – mikael1000 Dec 27 '16 at 13:58

1 Answers1

2

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

  1. Split the string by ., to separate different sentences
  2. Trim each sentence
  3. Capitalize first letter
  4. 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());
Tushar
  • 85,780
  • 21
  • 159
  • 179