在jsp或java中有没有查找子串在父串中位置的通用方法?

studiosky 2002-05-13 05:55:35
象这样的方法:
public int locateString(String parentString, String subString) {
...
}
我找不到,那位知道的请告诉我,thanks!
...全文
42 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
dylanwolf 2002-05-13
  • 打赏
  • 举报
回复
呵呵,没什么好答的了。
dylanwolf 2002-05-13
  • 打赏
  • 举报
回复
呵呵,没什么好答的了。
alphazhao 2002-05-13
  • 打赏
  • 举报
回复
不好意思,打错个地方
int i = par.indexOf(son);
i就是son字串在par字串中第一个匹配的位置
Apocalypse 2002-05-13
  • 打赏
  • 举报
回复
String的indexOf()和lastIndexOf()都可以用
肖尧19 2002-05-13
  • 打赏
  • 举报
回复
indexOf(String str)
Returns the index within this string of the first occurrence of the specified substring.

for example:
String s1="http://www.csdn.net/";
String s2="csdn";
int i=s1.indexOf(s2);
System.out.println("index:"+i);
alphazhao 2002-05-13
  • 打赏
  • 举报
回复
有个String的方法
String par;
String son;
……
int i = par.indexOf(str)就是str在par中的位置,如果没有匹配的,则i值为-1

81,092

社区成员

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

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