java实现查找替换功能
2019-04-11 09:17
543 查看
本文实例为大家分享了java实现查找替换功能的具体代码,供大家参考,具体内容如下
查找
if(searchTxt.getText().equals("")){ JOptionPane.showMessageDialog(null, "查找内容不能为空!"); }else if(!searchTxt.getText().equals("")){ //searchDialog.dispose(); if(fileChoose.focus == 1){ fileChoose.tp1.requestFocus(true); str = fileChoose.tp1.getText(); startPosition = str.indexOf(searchTxt.getText()); endPosition = startPosition + searchTxt.getText().length(); fileChoose.tp1.select(startPosition, endPosition); newEndPosition = endPosition; }else if(fileChoose.focus == 2){ fileChoose.tp2.requestFocus(true); str = fileChoose.tp2.getText(); startPosition = str.indexOf(searchTxt.getText()); endPosition = startPosition + searchTxt.getText().length(); fileChoose.tp2.select(startPosition, endPosition); newEndPosition = endPosition; } }
查找下一处
nextTemp = newEndPosition; if(fileChoose.focus == 1){ strAll = fileChoose.tp1.getText(); fileChoose.tp1.select(nextTemp, strAll.length());//选中所有未查找的字符串 nextStr = fileChoose.tp1.getSelectedText(); newStartPosition = nextStr.indexOf(searchTxt.getText()) + nextTemp;//在未查找的字符串中查找对应字符在tp1中的位置 newEndPosition = newStartPosition + searchTxt.getText().length(); fileChoose.tp1.select(newStartPosition, newEndPosition);//找到文本,选择文本 }else if(fileChoose.focus == 2){ strAll = fileChoose.tp2.getText(); fileChoose.tp2.select(nextTemp, strAll.length());//选中所有未查找的字符串 nextStr = fileChoose.tp2.getSelectedText(); newStartPosition = nextStr.indexOf(searchTxt.getText()) + nextTemp;//在未查找的字符串中查找对应字符在tp1中的位置 newEndPosition = newStartPosition + searchTxt.getText().length(); fileChoose.tp2.select(newStartPosition, newEndPosition);//找到文本,选择文本 }
替换
if(fileChoose.focus == 1){ fileChoose.tp1.requestFocus(true); str = fileChoose.tp1.getText(); startPosition = str.indexOf(searchTxt.getText()); endPosition = startPosition + searchTxt.getText().length(); fileChoose.tp1.replaceSelection(replaceTxt.getText()); newEndPosition = endPosition; }else if(fileChoose.focus == 2){ fileChoose.tp2.requestFocus(true); str = fileChoose.tp2.getText(); startPosition = str.indexOf(searchTxt.getText()); endPosition = startPosition + searchTxt.getText().length(); fileChoose.tp2.replaceSelection(replaceTxt.getText()); newEndPosition = endPosition; }
替换下一处
if(fileChoose.focus == 1){ fileChoose.tp1.requestFocus(true); nextTemp = newEndPosition; strAll = fileChoose.tp1.getText();//////////////////////////////// fileChoose.tp1.select(nextTemp, strAll.length());///////////////////////////// nextStr = fileChoose.tp1.getSelectedText(); newStartPosition = nextStr.indexOf(searchTxt.getText()) + nextTemp; newEndPosition = newStartPosition + searchTxt.getText().length(); fileChoose.tp1.select(newStartPosition, newEndPosition); fileChoose.tp1.replaceSelection(replaceTxt.getText()); }else if(fileChoose.focus == 2){ fileChoose.tp2.requestFocus(true); nextTemp = newEndPosition; strAll = fileChoose.tp2.getText(); fileChoose.tp2.select(nextTemp,strAll.length()); nextStr = fileChoose.tp2.getSelectedText(); newStartPosition = nextStr.indexOf(searchTxt.getText()) + nextTemp; newEndPosition =newStartPosition + searchTxt.getText().length(); fileChoose.tp2.select(newStartPosition, newEndPosition); fileChoose.tp2.replaceSelection(replaceTxt.getText()); }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
相关文章推荐
- java实现查找文本内容替换功能示例
- Java实现查找替换功能
- java 使用正则Pattern等实现【搜索 -> 提取 -> 分割 -> 替换】功能
- (二)C#使用DsoFramer操作Excel实现查找、替换的功能
- java学习总结(16.05.25)eclipse的查找和替换功能 Ctrl+F
- VB应用程序中实现查找和替换功能
- Word查找替换功能之快速实现行尾批量加句号
- Java基于正则表达式实现的替换匹配文本功能【经典实例】
- C#实现记事本查找与替换功能
- 自己做的java 记事本(查找,替换部分功能缺失) 多多交流
- 死亡历险,翻开新的一篇之Delphi 连接 JAVA WebService,并实现查找,添加,修改,删除等功能
- java实现单链表的初始化,创建,删除,插入,查找,排序,同项删除,退出等功能
- 用java编写程序实现查找磁盘上的文件的功能
- java 使用正则Pattern等实现【搜索 -> 提取 -> 分割 -> 替换】功能
- JAVA实现查找替换文本文件内容的例子
- 文本编辑器 “查找与替换”操作的“全部替换”功能的实现代码 Visual Basic 2005 编写
- java过滤敏感词实现字符串替换功能
- Java基于正则表达式实现查找匹配的文本功能【经典实例】
- java实现记事本基本功能:新建、打开、保存、另存为、退出、替换、全部替换、复制、剪切、粘贴、全选、获取当前时间日期、修改字体、颜色、自动换行等
- java实现数据结构-线性表-顺序表,实现插入,查找,删除,合并功能