What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » WLM Plus! Help » Auto capitalize

Auto capitalize
Author: Message:
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Auto capitalize
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:
js 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).

;)

This post was edited on 09-28-2011 at 06:12 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
09-28-2011 06:00 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Auto capitalize - by mplusfan on 09-28-2011 at 01:09 AM
RE: Auto capitalize - by Spunky on 09-28-2011 at 08:17 AM
RE: Auto capitalize - by mplusfan on 09-28-2011 at 12:33 PM
RE: Auto capitalize - by matty on 09-28-2011 at 12:48 PM
RE: Auto capitalize - by Spunky on 09-28-2011 at 03:22 PM
RE: Auto capitalize - by CookieRevised on 09-28-2011 at 06:00 PM
RE: Auto capitalize - by Spunky on 09-28-2011 at 06:12 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On