Guidance
指路人
g.yi.org
Guidance Forums / Rapid-Q Basic / File.WriteStr

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. File.WriteStr
#740
Posted by: 2003-01-17 18:43:05
This simple program works well, apparently, but makes something I don't understand.

File.Open("dati.txt", fmopenread)
mystring$=File.Readstr(File.Size)
File.Close
mystring$=Replacesubstr$(mystring$, "retta", "rettissima")
File.Open("dati.txt", fmopenwrite)
lung%=len(mystring$)
File.WriteStr(mystring$, lung%)
File.Close

It adds a space at the end of my text file every time I run it.
I made it work properly by giving the parameter lung% -1 in the WriteStr command, but still I'm puzzled.
Can someone tell me why it does this?

Thanks in advance.

Cajino
Message2. EOF
#743
Posted by: guidance 2003-01-22 11:02:40
I wonder whether it is EOF added by text mode filestream?
Message3. no no no!!
#744
Posted by: 2003-01-23 00:53:43
Hi There!

It  is the replacesubstr function,  technically.
if you check the result of  it  it will  return one
more  byte in length (the null character). in turn
the function is also 1 based  instead of zero
based so 8 will give a len of 9. No Problem?
yes, because filestream is zero based!
hence why you get an extra  byte. Remember.
filestream   is binary. Its not bothered about
eof+a space. The problems can occur   when reading
the file/length back in, if you   dont correct with -1.

regards

john

Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Thu 2024-3-28  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0