Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
removing a line from a text document
#16
Code:
Copy      Help
str a
a.getfile("$Desktop$\test.txt")
;a.RemoveLineN(4);; deletes line 5 from file
a.RemoveLineN(numlines(a)-1);; deletes last line of file
a.setfile("$Desktop$\test.txt")

You must have Member function str.RemoveLineN
(To add new Member function) while QM window is active press and release (Ctrl+Alt+N) this will add a new Member function make sure you name the new Member function (str.RemoveLineN), and add the below code to it.

str.RemoveLineN
Code:
Copy      Help
function# lineindex [nlines]

;Removes specified line(s).
;Returns index of first character of lineindex-th line, or -1 if lineindex is too big.


;lineindex - zero-based line index.
;nlines - number of lines to remove. Default or 0: 1 line.


;EXAMPLE
;str s="zero[]one[]two"
;s.RemoveLineN(1)
;out s



if(nlines<1) nlines=1
int i=findl(this lineindex)
if(i>=0) this.remove(i findl(this+i nlines))
ret i


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)