求记事本“查找下一个”代码

jie8171256 2011-06-17 04:33:12
编写查找的功能已经实现了,就是不知道怎么修改,是继续查找下一个字符,求指教!还有怎么样实现从后往前查找??

public void actionPerformed(ActionEvent se)
{
if(se.getSource() == findButton)
{

int a = 0,b = 0,FindStartPos = 0;
String str1,str2,str3,str4,strA,strB;
str1 = text.getText();
str2 = str1.toLowerCase();
str3 = searchField.getText();
str4 = str3.toLowerCase();
if(downBox.getState())
{
strA = str1;
strB = str3;
}
else
{
strA = str2;
strB = str4;
}
a = strA.indexOf(strB,FindStartPos);
if(a > -1)
{
text.setCaretPosition(a);
b = searchField.getText().length();
text.select(a,a+b);
FindStartPos = a+b;
}
else {
JOptionPane.showMessageDialog(null,"找不到\""+str3+"\"");
}
}
...全文
109 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
jie8171256 2011-06-17
  • 打赏
  • 举报
回复
我没运行那个程序,你看下我这个该怎么该?[Quote=引用 5 楼 ticmy 的回复:]

可以一直查找到文件末尾的啊

引用 4 楼 jie8171256 的回复:

那个代码我看过了,和我的差不多,只能查找第一个,不能继续查找了。
[/Quote]
huntor 2011-06-17
  • 打赏
  • 举报
回复
1 可以使用 regexp

2 String indexOf(String str, int fromIndex)
龙四 2011-06-17
  • 打赏
  • 举报
回复
可以一直查找到文件末尾的啊

[Quote=引用 4 楼 jie8171256 的回复:]

那个代码我看过了,和我的差不多,只能查找第一个,不能继续查找了。
[/Quote]
jie8171256 2011-06-17
  • 打赏
  • 举报
回复
那个代码我看过了,和我的差不多,只能查找第一个,不能继续查找了。
aotian16 2011-06-17
  • 打赏
  • 举报
回复
路过一下
chenchenyangll 2011-06-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ticmy 的回复:]

参考:http://hi.baidu.com/freish/blog/item/21a604f7c0271b28730eec61.html
[/Quote]

收藏了 = =

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧