SA-MP Forums Archive
String check - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: String check (/showthread.php?tid=436073)



String check - Jefff - 09.05.2013

Example:
pawn Код:
new str[] = "Nick (ID): Some Text\nNick (ID): Some Text\nNick (ID): Some Text\nNick (ID): Some Text\n";
pawn Код:
CheckMsg(str); // if line have more than 20 characters strdel a strins [...]
Result:
pawn Код:
str = "Nick (ID): Some [...]\nNick (ID): Some [...]\nNick (ID): Some [...]\nNick (ID): Some [...]";
Can someone show me how can I do this stock CheckMsg ?

Thats my stock but something is wrong with lengh += len;

pawn Код:
stock CheckMsg(txt[],s_size = sizeof(txt))
{
    new str[128],pos;
    pos = 4; // lines in txt[]
    new i,idx,lengh = 0;

    while(i != pos)
    {
        str = strtok(txt, idx, '\n');
        new len = strlen(str) + 2;
        printf("len: %d - %s",len,str);
        if(len-2 > MIN_TXT)
        {
            strdel(str,MIN_TXT,idx-1);
            strins(str," [...]",MIN_TXT);
            //print(str);

            len = strlen(str) + 1;
            strdel(txt,lengh,idx-1);
            strins(txt,str,lengh,s_size);
            print(txt);
        }
        lengh += len;
        //printf("lengh: %d",lengh);
        idx = len;
        i++;
    }
}



Re: String check - park4bmx - 09.05.2013

So u want if the string contains "\n" split it and store it in another string ?


Re: String check - Jefff - 09.05.2013

No if the string (one line) lenght > 20 strdel 20 to \n and strins in pos 20 [...] then go to the next line and do the same


Re: String check - Jefff - 10.05.2013

Thanks all for helping