Help to get a string.. - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Help to get a string.. (
/showthread.php?tid=193096)
Help to get a string.. -
The_Moddler - 24.11.2010
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:
How can I correct this?
Thanks
Re: Help to get a string.. -
Jefff - 25.11.2010
U want that effect?
pawn Код:
asdasda
adkaksd asD:D
akjsdkajd
Re: Help to get a string.. -
The_Moddler - 25.11.2010
No.. just:
Код:
asdasda adkaksd asD:D akjsdkajd
Re: Help to get a string.. -
Jefff - 25.11.2010
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");
}