AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   string reading problems (https://forums.alliedmods.net/showthread.php?t=193178)

SpaceRip 08-17-2012 08:18

string reading problems
 
Hello, i try to do something here

if text contains \x then do something and skip text "\x"
here is code
PHP Code:

            for (0127y++)
            {
                if ( !
m[y] )
                    break

                if( 
)
                {
                    
0
                    
continue
                }

                if ( 
m[y] == '\')
                {    
                    d = 1
                    c = str_to_num(m[y + 1])
                    print( i, "color %d - m: %s", c, m[y + 1] )
                    continue
                }


code run in loop, it check m[128] string variable the problem is that this fails somehow
sometime it crab a wrong thing, m[23] == '\' , m[24] == '1' , m[25] == '3'
and i will got 3 with this code, how is this possible?

Liverwiz 08-17-2012 13:41

Re: string reading problems
 
if(contain(m, "/x") != -1)
{
//The string contains /x
//this is what we do
}

SpaceRip 08-17-2012 14:08

Re: string reading problems
 
Quote:

Originally Posted by Liverwiz (Post 1774218)
if(contain(m, "/x") != -1)
{
//The string contains /x
//this is what we do
}

how you do this in loop with checking every sting char one by one?
PHP Code:

if(contain(m"/x"

it take all text what is inside m variable, i can controll or can not know where the place was where that /x.

Liverwiz 08-17-2012 14:23

Re: string reading problems
 
You don't loop it, that is the point. If you need to know where in the string /x is, cache the return of contain and use that. Contain returns the index of where the second argument is. Check out the wiki. then you'd take that index, add 2, and that is the start of w/e you're looking for.

Show the whole function so i know more of what you're trying to do.

Exolent[jNr] 08-17-2012 16:01

Re: string reading problems
 
Are you trying to convert \x## from HEX to an ASCII character?

SpaceRip 08-18-2012 14:59

Re: string reading problems
 
Quote:

Originally Posted by Liverwiz (Post 1774272)
You don't loop it, that is the point. If you need to know where in the string /x is, cache the return of contain and use that. Contain returns the index of where the second argument is. Check out the wiki. then you'd take that index, add 2, and that is the start of w/e you're looking for.

Show the whole function so i know more of what you're trying to do.

i think that "contain" function works same way as i tring to do but the question is why i fail.
So what i want to do is "Too much" to talk about it, many systems of mine will use that code.
But now on i just try to create code what can do Following things.
Sort tag-ed data into the correct string variable.
Add x char to all string variable where i sort data except that one what is in progress right now.
PHP Code:

int c // correct variable bound
int i

for ( 0hmax;i++ )
    if ( 
== )
        break 
// or // continue 

if it is x char then store it too all variable(s) bounds.

I really need to use loop and do every char one by one only then i can get unlimited opportunity, you never know what you need to do next time.
Its a big script and all my functions must have unlimited opportunity, ohter ways i will keep writing a code and it will get really too huge.
For no own, i dont know that if the size of the all plugin code takes more cpu if many functions is used very rarely, so im trying to keep it safe just for case.

Quote:

Originally Posted by Exolent[jNr] (Post 1774359)
Are you trying to convert \x## from HEX to an ASCII character?

No

lucas_7_94 08-18-2012 15:21

Re: string reading problems
 
strfind be an option ?

Well if you post whole funcion you will get a better answer.

Liverwiz 08-18-2012 19:10

Re: string reading problems
 
show your whole code. No one knows what you're trying to do. Because there are natives that do this better.

jimaway 08-19-2012 08:13

Re: string reading problems
 
you could use regex to find \x## from string and use replace() to replace that with empty string

SpaceRip 08-21-2012 16:26

Re: string reading problems
 
**Code removed**

I try one more time to make working code, this is just too badly coded.


All times are GMT -4. The time now is 05:41.

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