0 registered members (),
18,767
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Please help to write a program that removes the found string.
[Re: Superku]
#315972
03/20/10 14:37
03/20/10 14:37
|
Joined: Mar 2010
Posts: 26
Sergmodern
OP
Newbie
|
OP
Newbie
Joined: Mar 2010
Posts: 26
|
Here is my text of the program, but it deletes all the contents of the file.
function delete_tov()
{
var temp;
STRING* esc;
fihandle = file_open_read("strings1.dll"); // ôàéë ñîäåðæèò: j
j=file_var_read(fihandle); // òåïåðü j
file_close(fihandle);
fhandle = file_open_write("Tovar.txt"); // test.txt ñîäåðæèò "this,was,a,test"
inkey_active=0;inkey(mul);
for(i=0;i<j;i++)
{
file_seek(fhandle,temp,0);
file_str_write(fhandle," ");
// delete.alpha=0;
// delete1.alpha=100;
wait(1);
}
file_str_read(fhandle,acc1);
}
And it is looking for a line in the file.
function search_tov()
{
var temp1;
fhandle = file_open_read("strings1.dll"); // ôàéë ñîäåðæèò: j
j=file_var_read(fhandle); // òåïåðü j
file_close(fhandle);
fhandle = file_open_read("Tovar.txt"); // test.txt ñîäåðæèò "this,was,a,test"
inkey_active=0;inkey(mul);
temp1 = file_find(fhandle,mul);
if (temp1<0) str_cpy(ac,"Ñòðîêà íå íàéäåíà"); else
str_cpy(ac,"Íàéäåíà ñòðîêà:");
for(i=0;i<j;i++)
{
file_str_read( fhandle, acc);
break;
wait(1);
}
file_close(fhandle);
delete_tov();
}
|
|
|
Re: Please help to write a program that removes the found string.
[Re: Sergmodern]
#316053
03/21/10 03:02
03/21/10 03:02
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Check THIS THREAD out. It may be able to do the job for you. Otherwise its inner-workings may point you in the right direction.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Please help to write a program that removes the found string.
[Re: Sergmodern]
#316080
03/21/10 10:58
03/21/10 10:58
|
Joined: Sep 2009
Posts: 1,032 Budapest
Aku_Aku
Serious User
|
Serious User
Joined: Sep 2009
Posts: 1,032
Budapest
|
I am afraid, you can not delete one (or more) line with Lite-C or C-Script. AFAIK to do that, you have to make a loop to read the file, line by line, and write out those line what you want to keep into a new file. Here is a pseudo code: open for input(original file) open for write(temporary file) loop while(not EOF) read from(original) if(we need that line) write to(temporary) end if end loop close(original file) close(temporary file) delete(original file) rename(temporary to original)
Last edited by Aku_Aku; 03/21/10 11:18.
|
|
|
Re: Please help to write a program that removes the found string.
[Re: Aku_Aku]
#316083
03/21/10 11:22
03/21/10 11:22
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
This is the best I can think of, as I havent been near my file-handling code in a while. And Im not in a very "coding" frame of mind ATM, so following your code isnt working. Can your code find the data you want to remove, and its length in bytes? If so, then follow these steps with my code to remove that 'chunk' of data.
// Close the file in your code.
var LENGTH = [the number of bytes to remove];
var START = [the position of first byte to remove];
// ( the number of bytes from the start of the file ) //
var fhandle = file_open_RW(filename);
file_bytes_remove(fhandle, LENGTH, START, 0);
file_close_RW(fhandle);
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
|