Below lines are in A QPlainTextEdit:
I want to delete a matched line with line variable help. For example, I want to delete
line 2 s44 grade
with the help of line variable(line = "line 2")
I am able to delete the particular text with below code:
item = "line 2"
text = self.project_length_lanes_plainedit.toPlainText()
text = text.replace(item, '')
_list = text.split()
text = '\n'.join(_list)
self.project_length_lanes_plainedit.setPlainText(text)
but I want to delete the entire line. How can I do that?
I tried as below working:
item = "line 2"
text = self.project_length_lanes_plainedit.toPlainText()
for l in text.split('\n'):
if item in l:
text = text.replace(l, '')
_list = text.split('\n')
_list = [ i for i in _list if i ]
text = '\n'.join(_list)
self.project_length_lanes_plainedit.setPlainText(text)