AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Breaking socket data on lines? (https://forums.alliedmods.net/showthread.php?t=155759)

AoD90 04-26-2011 09:11

Breaking socket data on lines?
 
How can I break received socket data into lines so I can read line by line?

AoD90 04-26-2011 10:19

Re: Breaking socket data on lines?
 
nvm

I just used:

Code:

new ExplodedStrings[10][16]
       
        new Count = ExplodeString( ExplodedStrings, 10, 16, g_Data, '^n' )
       
        for(new i=0; i<=Count; i++)
        {
            log_amx("%s", ExplodedStrings[i])
        }

with
Code:

stock ExplodeString( p_szOutput[][], p_nMax, p_nSize, p_szInput[], p_szDelimiter )
{

    new nIdx = 0, l = strlen(p_szInput)
    new nLen = (1 + copyc( p_szOutput[nIdx], p_nSize, p_szInput, p_szDelimiter ))
    while( (nLen < l) && (++nIdx < p_nMax) )
    nLen += (1 + copyc( p_szOutput[nIdx], p_nSize, p_szInput[nLen], p_szDelimiter ))
    return nIdx
}


ProIcons 04-26-2011 20:00

Re: Breaking socket data on lines?
 
ehm , lets say
that your variable that the socket stores the new data is

data[900]

you can simple do it with

server_print("%s\n\r",data)

Exolent[jNr] 04-26-2011 20:04

Re: Breaking socket data on lines?
 
Quote:

Originally Posted by ProIcons (Post 1458597)
ehm , lets say
that your variable that the socket stores the new data is

data[900]

you can simple do it with

server_print("%s\n\r",data)

He wanted to find separate lines within the variable.

Example:
Code:
new data[128]; copy(data, charsmax(data), "oh, line #1^r^nline #2^r^nand look like #3!^r^n^r^na blank line betwen!");

To find those you would use the ExplodeString() like he did or this:

Code:
new line[32]; while(data[0]) {     strtok(data, line, charsmax(line), data, charsmax(data), '^n');         // line variable is one of those lines. }


All times are GMT -4. The time now is 04:18.

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