Freigeben über


String.IndexOf Method

Definition

Overloads

IndexOf(Int32)

Returns the index within this string of the first occurrence of the specified character.

IndexOf(String)

Returns the index within this string of the first occurrence of the specified substring.

IndexOf(Int32, Int32)

Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index.

IndexOf(String, Int32)

Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.

IndexOf(Int32)

Returns the index within this string of the first occurrence of the specified character.

[Android.Runtime.Register("indexOf", "(I)I", "")]
public int IndexOf (int ch);
[<Android.Runtime.Register("indexOf", "(I)I", "")>]
member this.IndexOf : int -> int

Parameters

ch
Int32

a character (Unicode code point).

Returns

the index of the first occurrence of the character in the character sequence represented by this object, or -1 if the character does not occur.

Attributes

Remarks

Returns the index within this string of the first occurrence of the specified character. If a character with value ch occurs in the character sequence represented by this String object, then the index (in Unicode code units) of the first such occurrence is returned. For values of ch in the range from 0 to 0xFFFF (inclusive), this is the smallest value k such that: <blockquote>

this.charAt(<i>k</i>) == ch

</blockquote> is true. For other values of ch, it is the smallest value k such that: <blockquote>

this.codePointAt(<i>k</i>) == ch

</blockquote> is true. In either case, if no such character occurs in this string, then -1 is returned.

Java documentation for java.lang.String.indexOf(int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

IndexOf(String)

Returns the index within this string of the first occurrence of the specified substring.

[Android.Runtime.Register("indexOf", "(Ljava/lang/String;)I", "")]
public int IndexOf (string str);
[<Android.Runtime.Register("indexOf", "(Ljava/lang/String;)I", "")>]
member this.IndexOf : string -> int

Parameters

str
String

the substring to search for.

Returns

the index of the first occurrence of the specified substring, or -1 if there is no such occurrence.

Attributes

Exceptions

if string is null.

Remarks

Returns the index within this string of the first occurrence of the specified substring.

The returned index is the smallest value k for which:

{@code
            this.startsWith(str, k)
            }

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

Java documentation for java.lang.String.indexOf(java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

IndexOf(Int32, Int32)

Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index.

[Android.Runtime.Register("indexOf", "(II)I", "")]
public int IndexOf (int ch, int fromIndex);
[<Android.Runtime.Register("indexOf", "(II)I", "")>]
member this.IndexOf : int * int -> int

Parameters

ch
Int32

a character (Unicode code point).

fromIndex
Int32

the index to start the search from.

Returns

the index of the first occurrence of the character in the character sequence represented by this object that is greater than or equal to fromIndex, or -1 if the character does not occur.

Attributes

Remarks

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. For values of ch in the range from 0 to 0xFFFF (inclusive), this is the smallest value k such that: <blockquote>

(this.charAt(<i>k</i>) == ch) {@code &&} (<i>k</i> &gt;= fromIndex)

</blockquote> is true. For other values of ch, it is the smallest value k such that: <blockquote>

(this.codePointAt(<i>k</i>) == ch) {@code &&} (<i>k</i> &gt;= fromIndex)

</blockquote> is true. In either case, if no such character occurs in this string at or after position fromIndex, then -1 is returned.

There is no restriction on the value of fromIndex. If it is negative, it has the same effect as if it were zero: this entire string may be searched. If it is greater than the length of this string, it has the same effect as if it were equal to the length of this string: -1 is returned.

All indices are specified in char values (Unicode code units).

Java documentation for java.lang.String.indexOf(int, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

IndexOf(String, Int32)

Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.

[Android.Runtime.Register("indexOf", "(Ljava/lang/String;I)I", "")]
public int IndexOf (string str, int fromIndex);
[<Android.Runtime.Register("indexOf", "(Ljava/lang/String;I)I", "")>]
member this.IndexOf : string * int -> int

Parameters

str
String

the substring to search for.

fromIndex
Int32

the index from which to start the search.

Returns

the index of the first occurrence of the specified substring, starting at the specified index, or -1 if there is no such occurrence.

Attributes

Exceptions

if subString is null.

Remarks

Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.

The returned index is the smallest value k for which:

{@code
                k >= Math.min(fromIndex, this.length()) &&
                              this.startsWith(str, k)
            }

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

Java documentation for java.lang.String.indexOf(java.lang.String, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to