What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Just adding a couple of lines, and my script doesn't work anymore!

Just adding a couple of lines, and my script doesn't work anymore!
Author: Message:
tj0nge
New Member
*


Posts: 1
Joined: Mar 2010
O.P. Just adding a couple of lines, and my script doesn't work anymore!
Hello, all of you.
I'm making a script, just for fun, and I don't think I'm ever going to publish it, just for learning, but I have a problem now. The script translates 'normal' language into binary code, and it works pretty good. at least, until I start to add symbols (!,/,*,&,%,$, etc...) to translate. Than I get an error message, wich says my script is broken or I do not have enough rights...

can anybody help?

PS:
[/code]function translate(Message)
{
       
        (...)
    Message = Message.replace(/<symbol/letter>/gi, "<binary code, like:    00100000> ");
    (...)
   
    return Message;
}[code]
03-31-2010 09:39 PM
Profile E-Mail PM Find Quote Report
foaly
Senior Member
****

Avatar

Posts: 718
Reputation: 20
38 / Male / Flag
Joined: Jul 2006
RE: Just adding a couple of lines, and my script doesn't work anymore!
did you escape the symbols that are used in regexps?
[signature.jpg]
03-31-2010 09:41 PM
Profile E-Mail PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Just adding a couple of lines, and my script doesn't work anymore!
Some symbols have special meanings in regular expressions (and strings). And thus you can't simply put them in, you need to escape them first. Hence:
quote:
Originally posted by foaly
did you escape the symbols that are used in regexps?


Escaping such symbols means you put the 'escape' symbol in front of them. For regular expressions (and many other subcode languages) the escape symbol is the slash: \

eg: Message = Message.replace(/\!/gi, "01010101");

Note: you must do the same for paths in strings. Or any occurence of the character \ in a string (if \ is meant to be taken as a literal character).
eg: var myPath = "C:\Documents"
will return an error, because \ is a special character (the escape symbol), so you must escape the escape symbol to make it a literal character:
eg: var myPath = "C:\\Documents"
the output of the myPath variable will be C:\Documents

--------------------

But as with many things: you can avoid the whole thing and make your script hundreds of lines and probably thousands of bytes shorter (and waaaay faster), by tackling your particular problem in the proper way:
Instead of doing a replace using regular expressions for each character, it would be way faster and shorter to simply take the decimal Ascii code (which is base 10) of the character and simply convert it into a binary code (base 2).
.-= A 'frrrrrrrituurrr' for Wacky =-.
04-01-2010 03:12 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »


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