Shoutbox

I need a little more help... - 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: I need a little more help... (/showthread.php?tid=63998)

I need a little more help... by dbgtrgr on 07-25-2006 at 10:50 PM

ok, I have a text file that has a line that goes:

<email>begininfo <info><email>endinfo

(Example: example@db.combegininfo w00texample@db.comendinfo)

that way I can search for <email>begininfo to find the beginning of the information, then look for <email>endinfo to find the end of the information so it can extract it.

From what I can tell this script should do the trick... But it's not working right :\

code:
if(Message == '!charname'){
        tf = fso.OpenTextFile(Path, ForReading, true);
        FileInfo = tf.ReadAll();
        tf.Close();
        var Start = FileInfo.indexOf(Contact.Email + 'begininfo');
        Start = Start + Contact.Email.length + 10;
        var End = CharInfo.indexOf(Contact.Email + 'endinfo');
        var Info = FileInfo.substr(Start,End);
        ChatWnd.SendMessage(Info);
}

RE: I need a little more help... by Shondoit on 07-25-2006 at 11:34 PM

code:
if(Message == '!charname'){
   tf = fso.OpenTextFile(Path, ForReading, true);
   FileInfo = tf.ReadAll();
   tf.Close();
   var Start = FileInfo.indexOf(Contact.Email + 'begininfo');
   Start = Start + Contact.Email.length + 10;
   var End = FileInfo.indexOf(Contact.Email + 'endinfo');
   var Info = FileInfo.substring(Start, End);
   ChatWnd.SendMessage(Info);
}
This should work
You wrote CharInfo, instead of FileInfo
and you wrote .substr this could work, but not in this way

you have 2 ways to extract text from a string...
substr and substring, the both take 2 params, but the second param is treated different, with substr this param is treated as the length after the starting point, and with substring this param is treated as ending point

But I would suggest using a better way, using Regular Expressions
code:
if(Message == '!charname'){
   tf = fso.OpenTextFile(Path, ForReading, true);
   FileInfo = tf.ReadAll();
   tf.Close();
   var Match = new RegExp(Contact.Email + "begininfo(.*)" + Contact.Email + "endinfo", "");
   //You could change this to:
   //"<" + Contact.Email + ">(.*)<\/" + Contact.Email + ">"]
   //That way you can write the text like
   //<example@db.com>w00t</example@db.com>
   //This should be more readable and more open for changes

   Match.test(FileInfo)
   Info = RegExp.$1
   ChatWnd.SendMessage(Info);

(I haven't tested this yet...)
It's a lot shorter...
It tries to match the string wich starts with Contact.Email + "begininfo"
Then "(.*)", the dot [.] says it should match every possible character, the asterisk [*] says it should match the preceding character 0 or more times, and its enclosed in parentheses [(] [)], so it is saved in the $1 variable of RegExp, then it matches Contact.Email + "endinfo" at the end

Look here for more information about RegExp's <Link>
RE: I need a little more help... by dbgtrgr on 07-25-2006 at 11:57 PM

hmm... Thank you ^^ You have been most helpfull. Especially about the substr substring thing... ^^