01-04-2007, 08:44 AM
Member function str.AddLine
Member function str.ReplaceLineN
Member function str.RemoveLineN
Member function str.InsertLineN
function $s
;Appends s as new line.
;EXAMPLE
;str sf
;sf.AddLine("line1")
;sf.AddLine("line2")
;...
if(this.len and !this.end("[]")) this+"[]"
this+s
this+"[]"
Member function str.ReplaceLineN
function# $replacement lineindex [nlines]
;Replaces specified line(s).
;Returns index of first character of lineindex-th line, or -1 if lineindex is too big.
;replacement - replacement string.
;lineindex - zero-based line index.
;nlines - number of lines to replace. Default or 0: 1 line.
;EXAMPLE
;str s="zero[]one[]two"
;s.ReplaceLineN("ONE" 1)
;out s
if(nlines<1) nlines=1
int i=findl(this lineindex)
if(i>=0)
,int j=findl(this+i nlines)
,if(j>=0) j-2; if(j<i or this[i+j]!=13) j+1
,this.replace(replacement i j)
ret i
Member function str.RemoveLineN
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
Member function str.InsertLineN
function# $insertstring lineindex
;Inserts line.
;Returns index of first character of lineindex-th line, or -1 if lineindex is too big.
;insertstring - string to be inserted. Does not have to end with new line.
;lineindex - zero-based line index where to insert insertstring.
;EXAMPLE
;str s="zero[]one[]two"
;s.InsertLineN("" 1) ;;inserts empty line
;out s
int i=findl(this lineindex)
if(i<0 and numlines(this)=lineindex) this+"[]"; i=this.len
if(i>=0)
,str s.from(insertstring "[]")
,this.insert(s i s.len)
ret i