#1903 files

fantlan Thu 7 Jun 2012

how do we delete a line of a file????

brian Thu 7 Jun 2012

lines := file.readAllLines
lines.removeAt(9)
file.out.print(lines.join("\n")).close

fantlan Thu 7 Jun 2012

thanks! But the problem is that we want to delete a line witch starts by a symbol (like //) so we don't know in witch line it is...

yliu Thu 7 Jun 2012

lines := file.readAllLines
lines.each |line,index| 
{
  if(line.startsWith(Str<|//|>)
    {
      lines.removeAt(index)
    }
}
file.out.print(lines.join("\n")).close

But I have no clue if that works because when you remove a line I think the index changes? So this is my extra paranoid safe approach.

lines := file.readAllLines
newlines := [,]
lines.each |line|
{
  if(!line.startsWith(Str<|//|>)
    {
      newlines.push(line)
    }
}
file.out.print(newlines.join("\n")).close

All of this is untested, but from the code you can kind of get some ideas of how to approach this.

qualidafial Fri 8 Jun 2012

I think you're looking for sys::List#findAll.

fantlan Tue 19 Jun 2012

thanks for your answers

Login or Signup to reply.