Help to get a string..
#1

I need to get something from the middle of a string, this is what I have:

pawn Код:
stock CorrectFile(const filename[])
{
    new buffer[256], buffer2[256], buffer3[256], sline1, count, startcount;
    new File: handle = fopen(filename, io_read);
    new File: tmp = fopen("part.part", io_write);
    fclose(tmp);
    tmp = fopen("part.part", io_append);
    while(fread(handle, buffer))
    {
        sline1 = strfind(buffer, '"');
        if(sline != -1)
        {
            strmid(buffer2, buffer, 0, sline1);
            format(buffer3, 256, "%s\r\n", buffer2);
            fwrite(handle, buffer3);
        }
    }
    fclose(handle);
    fclose(tmp);
    tmp = fopen("part.part", io_read);
    handle = fopen(filename, io_write);
    fclose(handle);
    handle = fopen(filename, io_append);
    while(fread(tmp, buffer))
    {
        fwrite(handle, buffer);
    }
    fclose(handle);
    fclose(tmp);
    fremove("part.part");
    return 1;
}
But the problem comes when I have more than a " in a single line, for example:

Код:
asdasda " adkaksd asD:D " akjsdkajd "
That will just write into the file:

Код:
asdasda
How can I correct this?

Thanks
Reply
#2

U want that effect?
pawn Код:
asdasda
 adkaksd asD:D
 akjsdkajd
Reply
#3

No.. just:

Код:
asdasda adkaksd asD:D akjsdkajd
Reply
#4

pawn Код:
stock CorrectFile(const filename[])
{
    new buffer[256], len;
    new File:handle,File:tmp;
    handle = fopen(filename, io_read);
    if(!handle) return printf("Warning: %s not exist",filename);
    tmp = fopen("part.txt", io_write);
    while(fread(handle, buffer))
    {
        len = strlen(buffer);
        for(new d; d < len-2; d++)
            if(buffer[d] == '"')
                strdel(buffer,d-1,d+1);
        fwrite(tmp, buffer);
    }
    fclose(handle);
    fclose(tmp);
    tmp = fopen("part.txt", io_read);
    handle = fopen(filename, io_write);
    while(fread(tmp, buffer))
        fwrite(handle, buffer);
    fclose(handle);
    fclose(tmp);
    return fremove("part.txt");
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)