Skip to content Skip to sidebar Skip to footer

How To Give Sentence Case To Sentences Through Css Or Javascript?

How to give sentence case to sentences through CSS or javascript? I've tried these CSS properties but these are different capitalize Transforms the first character of each word

Solution 1:

p:first-letter{text-transform:capitalize}

Capitalizes the first word of each sentence

Solution 2:

Something similar to this will work in JavaScript:

functionsentenceCase(theText) {
    return theText.toLowerCase().replace(/(^\s*\w|[\.\!\?]\s*\w)/g,function(c){return c.toUpperCase()});

}

Won't work perfectly in ALL cases, but, it might get you somewhere. There are a lot more elegant solutions on back-end languages, typically, though.

Solution 3:

what about:

str = "HeLlo Its aamiR here";str = str.substr(0,1).toUpperCase()+str.substr(1).toLowerCase()

Post a Comment for "How To Give Sentence Case To Sentences Through Css Or Javascript?"