300分问些简单的问题:关于String.indexOf()方法

gdsean 2002-01-17 03:21:57
indexOf方法用法如下
int index = "my name is SEAN".indexOf("SEAN");
这时index为11
index = "my name is SEAN".indexOf("sean");
这时index为-1
问题:
有没有办法让indexOf方法不区分大小写在字符串里面找到参数的位置??
使用其他工具类也是可以的。
BTW:
我做的事情是在html文件里面找标签,
如果全部变成小写容易找,但是有的内容要保持原来大小写
不变成小写又要写多很多东西

...全文
1273 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
gdsean 2002-01-30
  • 打赏
  • 举报
回复
楼上的XX,有没有搞错,我后悔给你点安慰分了
你自己回答的是什么东西你自己清楚,如果你是个程序员
很多话本来不用我多说,题目没看清楚你就别回答

foxwizard 2002-01-17
  • 打赏
  • 举报
回复

流氓,给那什么心250分?
只给俺10分?

我踩!!!!
当然是先打倒的说
gdsean 2002-01-17
  • 打赏
  • 举报
回复
你们是对的,对于我的愚蠢我感到遗憾
给分
xmvigour 2002-01-17
  • 打赏
  • 举报
回复
to gdsean(摇滚java) :
用个中间变量来过渡!

String source 为 <FORM action="http://somehost.com/Login.sp">
String source1=source.oLowerCase();
source1.indexOf("form")

z_yheart 2002-01-17
  • 打赏
  • 举报
回复
我这个方法不是转变字符的,是用来查找字符串的,例如
String str="<FORM action=\"http://somehost.com/Login.sp\">";
int i=indexOf(str,"FORM");
i就会返回1;但是str还是<FORM action="http://somehost.com/Login.sp">
没有变,你仍然可以进行你的操作,满足你的要求呀
gdsean 2002-01-17
  • 打赏
  • 举报
回复
wangtaoyy:你能解决再说
gdsean 2002-01-17
  • 打赏
  • 举报
回复
楼上各位能不能看懂我的意思呢?
我说了,把字符串变成小写不行
比如吧:
String source 为 <FORM action="http://somehost.com/Login.sp">
source.toLowerCase变成 <form action="http://somehost.com/login.jsp">
这里我要找form和action
source.indexOf("form")
但是Login.jsp也变成了login.jsp
那么这个action的内容也没用用了
jsp区分大小写的各位同志
当然还有变量和value等有些cgi也是区分大小写的
不能顾了头忘了尾啊


wangtaoyy 2002-01-17
  • 打赏
  • 举报
回复
这也值300分
你的分太多了就分一点吧
z_yheart 2002-01-17
  • 打赏
  • 举报
回复

public int indexOf(String sourceStr,String str)
{
String str1=sourceStr.toLowerCase();
String str2=str.toLowerCase();
int i=str1.indexOf(str2);
return i;
}
Patrick_DK 2002-01-17
  • 打赏
  • 举报
回复
同意楼上方法
z_yheart 2002-01-17
  • 打赏
  • 举报
回复
使用下面的方法

public void jMenuHelpAbout_actionPerformed(ActionEvent e) {
}
public int indexOf(String sourceStr,String str)
{
String str1=sourceStr.toLowerCase();
String str2=str.toLowerCase();
int i=str1.indexOf(str2);
return i;
}
foxwizard 2002-01-17
  • 打赏
  • 举报
回复
那就先全转成大写再找就不结了

62,634

社区成员

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

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