I want a string entered should be converted to sentence case in whatever case it is.
Like
hi all, this is derp. thank you all to answer my query.
be converted to
Hi all, this is derp. Thank you all to answer my query.
I want a string entered should be converted to sentence case in whatever case it is.
Like
hi all, this is derp. thank you all to answer my query.
be converted to
Hi all, this is derp. Thank you all to answer my query.
I came up with this kind of RegExp:
This is the solution I ended up using:
I wrote an FSM-based function to coalesce multiple whitespace characters and convert a string to sentence-case. It should be fast because it doesn't use complex regular-expression or
split
and assuming your JavaScript runtime has efficient string concatenation then this should be the fastest way to do it. It also lets you easily add special-case exceptions.Performance can probably be improved further by replacing the whitespace regexs with a function to compare char-codes.