2024-09-28 22:01:17 发布
网友
我需要从QTextEdit块中删除任意大小的字符集,并在替换字符中没有空格的地方用零替换它。你知道吗
QTextEdit
我知道cursor.insertText()和cursor.deleteChar()的方法 但是我需要一种不依赖于游标和操作系统的方法来处理QTextEdit块中的任意字符集
cursor.insertText()
cursor.deleteChar()
通过QTextEdit.toHtml()或toPlainText()获得字符串。你知道吗
QTextEdit.toHtml()
toPlainText()
因为你得到了一组简单的字符串,所以你只需要这样做。你知道吗
plaintext = QTextEdit.toPlainText() plaintext = plaintext.replace("the size of string","0"*len("the size of string") QTextEdit.setPlainText(plaintext)
在toHtml的例子中,您得到标签中的文本部分,并用它替换您喜欢的字符串。你知道吗
htmltext = QTextEdit.toHtml() htmltext = htmltext.replace("<p>your favorite strings<\p>","<p"+"0"*len(your favorite strings)+"<\p>") QTextEdit.setHtml(htmltext)
您可能需要提前通过lxml模块等分析html。 这对你来说是个好建议吗?你知道吗
lxml
通过
QTextEdit.toHtml()
或toPlainText()
获得字符串。你知道吗因为你得到了一组简单的字符串,所以你只需要这样做。你知道吗
在toHtml的例子中,您得到标签中的文本部分,并用它替换您喜欢的字符串。你知道吗
您可能需要提前通过
lxml
模块等分析html。 这对你来说是个好建议吗?你知道吗相关问题 更多 >
编程相关推荐