AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help with RegExp (?) (https://forums.alliedmods.net/showthread.php?t=172634)

Flipper_SPb 11-23-2011 16:40

Help with RegExp (?)
 
How to remove from string all ^x, where x is digit from 0 to 8 ?

Example:

^1P^8layer^0 -> Player

jim_yang 11-24-2011 03:15

Re: Help with RegExp (?)
 
\^[0-8] is the pattern
but amxx doesn't have regex_replace_all, and such simple case doesn't need to use regex.
Code:

void main()
{
        char a[] = "^1P^8layer^0";
        char b[100];
        int i = 0;
        int j = 0;
        char c;
        while(a[i])
        {
                if(a[i] == '^')
                {
                        c = a[i + 1];
                        if(c >= '0' && c <= '8')
                        {
                                i += 2;
                                continue;
                        }
                }
                b[j++] = a[i++];
        }
        b[j] = '\0';
        printf("%s\n", b);
        system("pause");
}

a C example.

Flipper_SPb 11-24-2011 04:03

Re: Help with RegExp (?)
 
Quote:

but amxx doesn't have regex_replace_all
Yes, I know :cry:

So, now I have:

PHP Code:

    replace_all(name31"^^0""")
    
replace_all(name31"^^1""")
    
replace_all(name31"^^2""")
    
replace_all(name31"^^3""")
    
replace_all(name31"^^4""")
    
replace_all(name31"^^5""")
    
replace_all(name31"^^6""")
    
replace_all(name31"^^7""")
    
replace_all(name31"^^8"""

Is that a good solution in my case?

jim_yang 11-24-2011 04:21

Re: Help with RegExp (?)
 
Don't you find any useful info from that example ? If so, sorry for wasting your time.

Flipper_SPb 11-24-2011 04:33

Re: Help with RegExp (?)
 
jim_yang, thanks a lot! But I don't know which one is more effective.

Arkshine 11-24-2011 04:38

Re: Help with RegExp (?)
 
It's not that hard to figure out. See the content of replace_all, see the content of his function. Now, when you see replace_all does much things by calling severals natives and you want to call it 9 times, vs the simple Jim's function called one time without calling natives ; it should be obvious, isn't it ?


All times are GMT -4. The time now is 08:30.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.