Removing Line Feeds From Editor.getLine()

Ron Jensen
2013-09-26
2013-09-26
  • Ron Jensen
    Ron Jensen
    2013-09-26

    I have a bunch of data that looks like:
    123
    456
    678
    aaa
    bbb
    ccc

    And need to get it into the form:

    123    aaa
    456    bbb
    789    ccc
    

    I wrote a little python script that usually works, but if there isn't a line-feed on the last line I lose the last two letters in that line. So the last line would look like "789 c". Is there a more intelligent way to get a line w/out line endings than editor.getLine(stride+i)[:-2])

    Thanks,

    Ron

    stride=editor.getLineCount()/2
    
    i=0
    while (i<stride):
     editor.gotoPos(editor.getLineEndPosition(i))
     editor.addText("\t" + editor.getLine(stride+i)[:-2])
     i += 1
    
     
  • dail8859
    dail8859
    2013-09-26

    Although I don't have any means of testing this currently, you should be able to use the rstrip() method for strings.

    # instead of this
    editor.getLine(stride+i)[:-2]
    # use this
    editor.getLine(stride+i).rstrip()
    

    This will strip all whitespace and non printing characters from the right side of a string.

     
  • Ron Jensen
    Ron Jensen
    2013-09-26

    dail8859,

    That works, thank you!