java如何在当前打开的编辑器中用另一个字符串替换特定字符串?
嗨,我正在做一个eclipse插件项目来创建一个IDE。在我的IDE中 检查当前打开的编辑器是否有特定字符串,并应 替换为在侧面的文本框中输入的字符串 看法我可以访问编辑器,但如果我搜索特定的 字符串,并用用户输入的输入替换该字符串 这不管用
IDocumentProvider provider=((AbstractTextEditor) ieditorpart).getDocumentProvid();
IDocument doc = provider.getDocument(ieditorpart.getEditorInput());
String content = doc.get();
pos=content.compareTo("\\/\\*ProbeEnd\\*\\/");
doc.replace(pos,5, "hello");
但这不管用。。。在这里,我刚刚给出了替代品 字符串为hello,但该值应取自文本框
访问编辑器有错误吗?我应该用这个吗 有什么方法可以做到这一点,或者有什么方法可以实现这一点?可以 有人帮我吗
# 1 楼答案
从编辑器中调用firePropertyChange(IEditorPart.PROP_INPUT)
# 2 楼答案
为什么变量“pos”是compareTo值(-1,0,1)?compareTo返回两个字符串的字典顺序
IDocument的替换方法有三个参数:
例如: