Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Finding string in TXT file
Message
From
25/12/2022 18:25:16
 
 
To
25/12/2022 11:50:48
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01685605
Message ID:
01685614
Views:
53
Hi Zoran.

You could read and write the file using the low level file functions something like this -
lnHandle = fopen("YourFile", 2)
lcData = ""
do while !feof(M.lnHandle)
	lcData = lcData + Fread(M.lnHandle)
EndDo

* Put your current code that proccesses the string here

Fchsize(M.lnHandle, 0)
Fseek(M.lnHandle, 0)
Fwrite(M.lnHandle, M.lcData)
Fclose(M.lnHandle)
That would be the same as using FileToStr and StrToFile, except that it doesn't release the file handle until it's done so you shouldn't have the problem your seeing.

Ian Simcock.

>Sorry for a lack of information. Yes, I need to write it back in the same file. File is a small, couple of kb.
>There is a procedure: I receive a file from a service (cyrilyc and latinic letters) which I should transform all to latinic. Some of lines in a file is longest than 254bytes. After transformation I search for a specific strings, remember variables and write it down to database. After that I delete file.
>
>
>If you give a better description of what you really want to achieve, we can help you better.
>
>You don't only want to search a file, you also want to write it back, which is new information. And when you write it back, is it to the same file name, or a new?
>
>Also, please tell us roughly how big the files are.
>
>The more information you give, the better.
>
>>On slow computers when I issue FILETOSTR(), then some proccesing and then STRTOFILE() back, sometimes error file access denied occurs. I don't want to slow down program while proccesing because of few users :-(. So, I'm looking for a possible different solution.
>>
>>May I ask what's wrong with using FileToStr()?
>>
>>>Line lenght can be more than 254 bytes and before the time of proccesing I don't know lenght of a specific line.
>>>
>>>You can use FGET to read text file line by line and compare
>>>
>>>>Any ideas how to find string between two unique strings in TXT file without using FILETOSTR command?
>>>>For example I need to find string
>>>>
>>>>aa
>>>>bb
>>>>cc
>>>>
>>>>in TXT file
>>>>
>>>>1111
>>>>2222
>>>>3333
>>>>first string:aa
>>>>bb
>>>>cc
>>>>second string:fsdfsdfs
>>>>444
>>>>555
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform