• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Detecting part of a string

Status
Not open for further replies.
Level 3
Joined
Jan 7, 2008
Messages
45
I would like to know if there is a way to detect parts of a string (Not substring), i'm talking a boolean comparison, where if a string i define contains something else i define as a substring, then it returns true, otherwise it returns false.
Not that i wouldn't be able to make it by using loops, i would just really like to know, so you won't have to guide me if there's no way :p

Well... i solved it while waiting, and for anyone interested i used this method:
JASS:
loop
    set udg_Ok=0
    set udg_N=0
    exitwhen udg_N>StringLength(<string>)
        set udg_N=udg_N+1
        if (SubString(<string>,udg_N,udg_N+7)=="Missile") then
        set udg_Ok=1
     endif
endloop
In this example i am scanning for the keyword missile
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
I strongly advise against this method.
It will generate massive ammounts of string leaks (yes strings do not gen destroyed in WC3, only recycled) and also repeats a usless number of times (you start substrining characters from a string which do not exist as they are out of range).

The most leak free way sadly is to break it down into characters (as the same strings get recycled so do not leak) and check character at a time.

Infact, the sentance above if passed through this function will generate like 50 strings with near no recycle ability as they are so unique.
 
Level 9
Joined
Nov 28, 2008
Messages
704
DSG, are string leaks really *that* important? I mean, the function efficiencies your talking about result in:

JASS:
    int Find(string text, string toFind):
        string array textArray
        string array findArray
        int textLength = StringLength(text)
        int findLength = StringLength(toFind)
        int searchLength = textLength - findLength
        int i = 0
        int ii
        string firstChar = SubString(toFind, 0, 1)
        bool found
        
        if toFind == "":
            return -1
        
        loop:
            exitwhen i == textLength
            textArray[i] = SubString(text, i, i + 1)
            i++
            
        i = 1
        
        loop:
            exitwhen i == findLength
            findArray[i] = SubString(toFind, i, i + 1)
            i++
        
        i = 0
        
        loop:
            exitwhen i > searchLength
            if firstChar == textArray[i]:
                //We check the rest of the string, as we have a potential candidiate.
                ii = 1
                found = true
                loop:
                    exitwhen ii == findLength
                    if findArray[ii] != textArray[ii + i]:
                        found = false
                        exitwhen true
                        
                    ii++
                
                if found:
                    return i
                    
            i++
        
        return -1

Which is easily 3x as large as his code. It doesnt seem worth it, really. Although, it's not like it took *that* long to make.
 
Level 3
Joined
Jan 7, 2008
Messages
45
Leaks aren't really that important as this isn't a "game map", this was posted under maps as Effect Browser, and is mainly meant to help map makers find effects for their abilites.

Leaks are never a good thing, however, in this case it's not very important.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
WC3 strings use a hash based table system (as far as I can tell).
Like all hash systems, as the number of elements increases, efficency decreases (as more looping occurs).

Basically, after too many unique strings, any string creation opperations take forever due to it having to find a string.
Just run a timer that 100 times a second prints out the previous printed number + 1. Eventually you will notice FPS dropping until a level of unplayable is reached. This is a common problem with debugging, causing people to think that other parts of their code leak when infact its the debugging which is.
 
Status
Not open for further replies.
Top