Room Tag Scanner sscanf tag

Results 1 to 6 of 6
  1. #1
    Member Sahar is offline
    MemberRank
    Apr 2015 Join Date
    Qiryat Yam, IsrLocation
    80Posts

    happy Room Tag Scanner sscanf tag

    guys how i can add tags to scan like [G=Numer] / [S=Number]


  2. #2
    Member Sahar is offline
    MemberRank
    Apr 2015 Join Date
    Qiryat Yam, IsrLocation
    80Posts

    Re: Room Tag Scanner sscanf tag

    Help ?

  3. #3
    Valued Member grandao is offline
    MemberRank
    Feb 2008 Join Date
    RJ - BrasilLocation
    128Posts

    Re: Room Tag Scanner sscanf tag

    If you are using Visual Studio 2012 the following will work (otherwise no support)
    Code:
    #include <regex>
    #include <string>
    
    int getTagNumber(const char *tag, const char *text)
    {
        // \[tag=(\d+)\]
        std::string pattern = "\\[";
        pattern.append(tag).append("=(\\d+)\\]");
    
        std::cmatch match;
        std::regex r(pattern);
    
        if (std::regex_search(text, match, r))
            return atoi(match[1].first);
    
        return -1;
    }
    How to use:
    Code:
    int value = getTagNumber("G", "My room name [G=31416]");
    // value = 31416
    
    value = getTagNumber("S", "My room name [G=31416][S=123]");
    //value = 123
    If the tag does not exists it will return -1.

  4. #4
    Good Guy George qet123 is offline
    MemberRank
    Apr 2009 Join Date
    DesertLocation
    1,432Posts

    Re: Room Tag Scanner sscanf tag

    Quote Originally Posted by grandao View Post
    If you are using Visual Studio 2012 the following will work (otherwise no support)
    Code:
    #include <regex>
    #include <string>
    
    int getTagNumber(const char *tag, const char *text)
    {
        // \[tag=(\d+)\]
        std::string pattern = "\\[";
        pattern.append(tag).append("=(\\d+)\\]");
    
        std::cmatch match;
        std::regex r(pattern);
    
        if (std::regex_search(text, match, r))
            return atoi(match[1].first);
    
        return -1;
    }
    How to use:
    Code:
    int value = getTagNumber("G", "My room name [G=31416]");
    // value = 31416
    
    value = getTagNumber("S", "My room name [G=31416][S=123]");
    //value = 123
    If the tag does not exists it will return -1.
    Code:
    ZGetGameClient()->GetStageName()
    no more support xd

  5. #5
    Member Sahar is offline
    MemberRank
    Apr 2015 Join Date
    Qiryat Yam, IsrLocation
    80Posts

    Re: Room Tag Scanner sscanf tag

    grandao i'm using visual studio 2003 it's will be work ?

  6. #6
    Valued Member grandao is offline
    MemberRank
    Feb 2008 Join Date
    RJ - BrasilLocation
    128Posts

    Re: Room Tag Scanner sscanf tag

    Quote Originally Posted by Sahar View Post
    grandao i'm using visual studio 2003 it's will be work ?
    No it won't work. For VS2003 or any other version use this one:
    Code:
    int getTagNumber(const char *tag, const char *text)
    {
        char buf[20];
        int i = strlen(tag);
        if (i > 17) return -1;
        sprintf(buf, "[%s=", tag);
        const char *pos = strstr(text, buf);
        if (!pos) return -1;
        char *end;
        double value = strtod(pos + i + 2, &end);
    
        if (*end == ']' && end != pos + i + 2)
            return value;
        return -1;
    }
    Last edited by grandao; 16-08-15 at 05:11 AM. Reason: fix code



Advertisement