Guidance
指路人
g.yi.org
Guidance Forums / Rapid-Q Basic / Overwrite one line in textfile

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

  
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Overwrite one line in textfile
#4910
Posted by: OvalX 2004-07-29 15:59:32
Hi coders,
I have simply text file with 10 lines (something like INI file) - creating is no problem. In this file I need later overwrite one line only (for example 3. line) by actuall text without corrupting other lines. I tried File.WriteLine (myText), but WriteLine has CRLF, which corrupts 4. line. Mayby your hint is simply, I welcome it. Thanx. Slavo
Message2. Re: Overwrite one line in textfile
#4916
Posted by: 2004-07-30 06:01:32
Ovalx,

Here is an example using QStringList to edit a text file line content.

 $APPTYPE CONSOLE

 DIM lst AS QSTRINGLIST
 lst.additems "this is line 1",_
  "this is line 2",_
  "this is line 3"
 lst.savetofile("testline.txt")
 lst.clear

showlist:
 WITH lst
  .loadfromfile("testline.txt")
  ?
  ?"List of content testline.txt"
  ?"----------------------------"
  ?.text
  ?"----------------------------"
  INPUT "press enter to continue...";k$
 END WITH

 IF isdone THEN GOTO jumpequal

 editline = 3
' read line and edit it
 new3$ = lst.item(editline-1) + " was edited"
' update the file content
 lst.insertitem editline-1, new3$
 lst.delitems editline
' delete old text on line 4
 lst.savetofile("testline.txt")
 isdone = 1
' re-display file content
 GOSUB showlist

jumpequal:
 lst.clear
 END
greetings,

don.
Message3. Re: Overwrite one line in textfile
#4917
Posted by: OvalX 2004-07-30 16:02:31
Hi don,
it works good, how simply! Thank you very much.
Have a nice day... Slavo
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Tue 2024-3-19  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0