91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

java實現查找替換功能

發布時間:2020-10-20 11:48:07 來源:腳本之家 閱讀:164 作者:cat_pp 欄目:編程語言

本文實例為大家分享了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());
    }

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

嘉义市| 阿瓦提县| 清涧县| 泸定县| 营口市| 黄石市| 江川县| 乐山市| 奉节县| 平乐县| 临桂县| 苏州市| 丰镇市| 南投市| 余江县| 葫芦岛市| 元朗区| 乐昌市| 北宁市| 邮箱| 登封市| 崇礼县| 洪湖市| 高邑县| 沈丘县| 金堂县| 横山县| 宁武县| 浙江省| 会泽县| 德钦县| 西吉县| 同心县| 元阳县| 巴彦淖尔市| 西藏| 大港区| 海南省| 自治县| 石屏县| 闸北区|