Just adding a couple of lines, and my script doesn't work anymore! - Printable Version -Shoutbox (https://shoutbox.menthix.net) +-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58) +--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4) +---- Forum: Scripting (/forumdisplay.php?fid=39) +----- Thread: Just adding a couple of lines, and my script doesn't work anymore! (/showthread.php?tid=94263) Just adding a couple of lines, and my script doesn't work anymore! by tj0nge on 03-31-2010 at 09:39 PM
Hello, all of you. RE: Just adding a couple of lines, and my script doesn't work anymore! by foaly on 03-31-2010 at 09:41 PM did you escape the symbols that are used in regexps? RE: Just adding a couple of lines, and my script doesn't work anymore! by CookieRevised on 04-01-2010 at 03:12 AM
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: 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). |