had a few minutes to spare and it was a long long time since I used regular expressions (and even Plus! scripting for that matter), so...
A few things with Spunky's code:
1) It does not capitalize the first word in a string
"hello world." stays "hello world."
2) Multiple spaces after a period are not taken in account.
"test1. test2" stays "test1. test2"
3) Character is not capitalized after an exclamation mark.
"test1! test2" stays "test1! test2"
4) substring(0, 1) => charAt(0)
though, this is just a very tiny detail, or personal preference if you will.
--
Either way, much shorter code using pure regular expressions:Javascript code:
function OnEvent_ChatWndSendMessage(ChatWnd, Message){
return Message.replace(/^\s*.|(\.|!)\s+./gm, function(a) {return a.toUpperCase()})
}
This also capitalizes the first word of a string.
Multiple spaces are taken in account.
It also capitalizes after an exclamation mark.
It even capitalizes when a new line character is encountered.
Example string:
" hello world. this is another sentence! this too. and this. HTML stays capitalized...this not\nthis will be capitalized too."
Output result:
" Hello world. This is another sentence! This too. And this. HTML stays capitalized...this not
This will be capitalized too."
Important note: I would never use something like that with the
OnEvent_ChatWndSendMessage() event as-is though. Code like that can 'corrupt' URLs and other stuff (like literal raw commands) which should not be threated as a pure text. So be very carefull with something like this! It is a nice programming exercise to make something like this, but in practice I highly recommend to never ever use it.
So, mplusfan, you could use code like above. But in practice it will always corrupt certain stuff which you do not want! It is much better to simply remember to capitalize sentences manually instead of being 'lazy' (for the lack of a better word).