indexOf()小问题求教

yashiro3003 2003-08-21 04:26:05

public int indexOf(String str,int fromIndex)。

那位dx可以详细讲解一下fromIndex这个参数是干什么的!
...全文
71 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
yashiro3003 2003-08-22
  • 打赏
  • 举报
回复
明白了。谢谢!
xuetinge 2003-08-21
  • 打赏
  • 举报
回复
呵呵,是我在误导了。
我刚刚查了一下,正觉得命名奇怪呢,
是巧合。

错了,
cricketlj 2003-08-21
  • 打赏
  • 举报
回复
public int indexOf(String str,
int fromIndex)
Returns the index within this string of the first occurrence of the specified substring, starting at the specified index. The integer returned is the smallest value k for which:
k >= Math.min(fromIndex, str.length()) && this.startsWith(str, k)

If no such value of k exists, then -1 is returned.

Parameters:
str - the substring for which to search.
fromIndex - the index from which to start the search.
Returns:
the index within this string of the first occurrence of the specified substring, starting at the specified index.
Throws:
NullPointerException - if str is null
李欣欣1981 2003-08-21
  • 打赏
  • 举报
回复
xuetinge(薛挺) ,不是这个意思吧。
api says:

Parameters:
str - the substring to search for.
fromIndex - the index to start the search from.

意思很明显,就是从第几个开始往后找。
hayai 2003-08-21
  • 打赏
  • 举报
回复
喷血!!!!

Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index.
If a character with value ch occurs in the character sequence represented by this String object at an index no smaller than fromIndex, then the index of the first such occurrence is returned--that is, the smallest value k such that:

(this.charAt(k) == ch) && (k >= fromIndex)
xuetinge 2003-08-21
  • 打赏
  • 举报
回复
拜托,不要误导了,
是前面指定字符第N次出现的位置
先原谅自己 2003-08-21
  • 打赏
  • 举报
回复
从fromIndex 开始向后查找
hayai 2003-08-21
  • 打赏
  • 举报
回复
就是从第几个字符开始找起,在这个字符前面的忽略。建议看看sun的api doc.

62,614

社区成员

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

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