Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 25

Thread: file_to_map

  1. #1
    Senior Member Pazleysox's Avatar
    Join Date
    Feb 2009
    Posts
    348

    Default file_to_map

    I haven't started coding this yet, but is it possible to pull a specific line from a map?

    For example:
    text.txt contains this data:
    0 (date/time)
    1 Council of Loathing
    2 Madame Zatara
    3 IotM
    4 (my clan_name)

    I want to be able to access lines 3, & 4.

    Is this even possible?

  2. #2
    Senior Member ckb's Avatar
    Join Date
    Mar 2006
    Posts
    802

    Default

    PHP Code:
        string [inttextmap;
        
    file_to_map("text.txt",textmap);
        print(
    textmap[3]);
        print(
    textmap[4]); 

  3. #3
    Senior Member Pazleysox's Avatar
    Join Date
    Feb 2009
    Posts
    348

    Default

    Scratch that...
    Last edited by Pazleysox; 04-12-2018 at 03:53 PM.

  4. #4
    Senior Member Pazleysox's Avatar
    Join Date
    Feb 2009
    Posts
    348

    Default

    Is there a way I can tell the map_to_file to skip the first 2, or 3 words that it's going to return?

    For Example:
    For example:
    text.txt contains this data:
    0 This is not a message
    1 Council of Loathing said "Are you ready to crawl into the science donation vessel and perform your final service to the community?"
    2 Madame Zatara
    3 The current IotM is: (this is what it is)

    line 1, I only want "Are you ready to crawl into the science donation vessel and perform your final service to the community?"
    line 3, I only want (this is what it is)

    Is that possible?

  5. #5
    Developer Veracity's Avatar
    Join Date
    Mar 2006
    Location
    The Unseelie Court
    Posts
    11,281

    Default

    No. That function returns whatever is in your file. You have two choices:

    1) Make sure the data in the file is in the form you want it to be
    2) Write code in your script to process what is in the file into the form you want it to be

  6. #6
    Senior Member Pazleysox's Avatar
    Join Date
    Feb 2009
    Posts
    348

    Default

    I found a this (now modified) code in the forum
    Code:
    void main() {
    
        matcher m;
    string raidlog = visit_url("shop.php?whichshop=generalstore");
    	m = create_matcher("was a ([a-z]*)", raidlog);
        if (find(m)) {
            print ("test");
            print(group(m,1));
        }
    which produces this:
    > call scripts\00TEST.ash

    test
    hero
    Code:
    void main() {
    
        matcher m;
    string raidlog = visit_url("shop.php?whichshop=generalstore");
    	m = create_matcher("was a (\\w*)", raidlog);
        if (find(m)) {
            print ("test");
            print(group(m,1));
        }
    produces the same thing. Is there a regex command to pull ALL the following text? I tried various things like this:
    (\\w*) (\\w*), and [a-z]* [a-z]* [a-z]*
    but I got the same output each time.

    I would like it to say this "hero of the Cola Wars. Now I wage war"

  7. #7
    Developer
    Join Date
    Apr 2010
    Posts
    4,394

    Default

    I always test my regexes using a regex tester first. I use http://www.regexplanet.com/advanced/java/index.html, but there are plenty out there.

  8. #8
    Developer
    Join Date
    Aug 2009
    Posts
    2,740

    Default

    " " isn't matched by \w or [a-z]+. Similarly, "." isn't matched by any of those groups.

    I'd probably use something like [^<]+ to match everything until the start of the next HTML tag.

    edit: also, note that m.group(1) will only return the first capturing group, i.e. what's in the first set of parentheses.

  9. #9
    Senior Member Pazleysox's Avatar
    Join Date
    Feb 2009
    Posts
    348

    Default

    " " isn't matched by \w or [a-z]+. Similarly, "." isn't matched by any of those groups.

    I'd probably use something like [^<]+ to match everything until the start of the next HTML tag.

    edit: also, note that m.group(1) will only return the first capturing group, i.e. what's in the first set of parentheses.
    Originally Posted by heeheehee View Post
    Code:
    	m = create_matcher("was ([^<]+)", raidlog);
        if (find(m)) {
            print ("test");
    	print(m);
            print(group(m,1));
    Got this to work. Here's my results:

    test
    was ([^<]+)
    a hero of the Cola Wars. Now I wage war against high prices!

    Now, how can I put that into a map?
    Last edited by Pazleysox; 04-13-2018 at 06:07 PM.

  10. #10
    Senior Member Pazleysox's Avatar
    Join Date
    Feb 2009
    Posts
    348

    Default

    I've tried these, but I keep coming up with errors...

    map_to_file(group(m,1), "test.txt");
    map_to_file((m,1), "test.txt");
    map_to_file(m, "test.txt");
    map_to_file(group(m), "test.txt");

    string savetofile = group(m,1);

    map_to_file(savetofile, "test.txt");

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •