Java实现查找替换功能
来源:互联网 发布:mac怎么改 编辑:程序博客网 时间:2024/05/17 10:05
查找
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()); }
1 0
- Java实现查找替换功能
- 通过正则实现Java记事本中查找和替换功能
- java实现查找文本内容替换功能示例
- 在SynEdit 中实现查找和替换功能
- VB应用程序中实现查找和替换功能
- VB应用程序中实现“查找和替换”功能
- word、dreamweaver查找替换功能
- emacs查找和替换功能
- java字符串查找替换
- java字符串查找替换
- java字符串查找替换
- java过滤敏感词实现字符串替换功能
- 文本编辑器 “查找与替换”操作的“全部替换”功能的实现代码 Visual Basic 2005 编写
- javascript 实现查找与替换
- String对象与正则表达式实现匹配、查找和替换功能
- (二)C#使用DsoFramer操作Excel实现查找、替换的功能
- Word查找替换功能之快速实现行尾批量加句号
- 自己做的java 记事本(查找,替换部分功能缺失) 多多交流
- iOS app打包测试及相关问题解决
- hibernate抓取策略fetch具体解释
- org.apache.commons.lang.ArrayUtils
- TableView分割线左对齐
- 40个Java多线程问题总结
- Java实现查找替换功能
- Cell上删除按钮
- 27个漂亮的移动端注册/登录界面设计作品
- 13、EL表达式简介
- apt-get update 和 upgrade 的区别
- 爬虫第一次
- 开启博客之旅
- 通过java.net.URLConnection发送HTTP请求的方法
- jni生成头文件