Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
replace line
#7
Member function str.AddLine
Code:
Copy      Help
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
Code:
Copy      Help
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
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

Member function str.InsertLineN
Code:
Copy      Help
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


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)