从文本中删除一行 [英] Removing a line from text

查看:124
本文介绍了从文本中删除一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个文本文件.我有一行,我想删除该行上的文本并将其替换为其他文本.我该怎么做呢?在文档上没有关于此的任何信息,在此先感谢!

Say I have a text document. I have a line.I want to delete the text on that line and replace it with another text. How do I do this? There is nothing for this on the docs, thanks in advance!

推荐答案

要替换QScintilla中的一行,您需要先选择该行,如下所示:

To replace a line in QScintilla, you need to first select the line, like this:

    # as an example, get the current line
    line, pos = editor.getCursorPosition()
    # then select it
    editor.setSelection(line, 0, line, editor.lineLength(line))

选中该行后,您可以将其替换为:

Once the line is selected, you can replace it with:

    editor.replaceSelectedText(text)

如果要用另一行替换该行(将在此过程中将其删除):

If you want to replace a line with another line (which will be removed in the process):

    # get the text of the other line
    text = editor.text(line)
    # select it, so it can be removed
    editor.setSelection(line, 0, line, editor.lineLength(line))
    # remove it
    editor.removeSelectedText()
    # now select the target line and replace its text
    editor.setSelection(target, 0, target, editor.lineLength(target))
    editor.replaceSelectedText(text)        

这篇关于从文本中删除一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆