XEnumerableIndexOfSubstringTSource Method |
Returns the position of the first occurrence of the specified substring in the source sequence, or -1 if it is not found.
Namespace:
Linq.Extras
Assembly:
Linq.Extras (in Linq.Extras.dll) Version: 5.0.0+96a4f4bfed64095342c5df107c1fe1fb95603ee5
Syntaxpublic static int IndexOfSubstring<TSource>(
this IEnumerable<TSource> source,
IEnumerable<TSource> substring,
IEqualityComparer<TSource>? comparer = null
)
<ExtensionAttribute>
Public Shared Function IndexOfSubstring(Of TSource) (
source As IEnumerable(Of TSource),
substring As IEnumerable(Of TSource),
Optional comparer As IEqualityComparer(Of TSource) = Nothing
) As Integer
[<ExtensionAttribute>]
static member IndexOfSubstring :
source : IEnumerable<'TSource> *
substring : IEnumerable<'TSource> *
?comparer : IEqualityComparer<'TSource>
(* Defaults:
let _comparer = defaultArg comparer null
*)
-> int
Parameters
- source
- Type: System.Collections.GenericIEnumerableTSource
The sequence to search for a substring. - substring
- Type: System.Collections.GenericIEnumerableTSource
The substring to search. - comparer (Optional)
- Type: System.Collections.GenericIEqualityComparerTSource
The comparer to use to test equality between elements.
Type Parameters
- TSource
- The type of the elements of source.
Return Value
Type:
Int32The zero-based index of the start of the first occurrence of
substring if it's found; otherwise, -1.
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type
IEnumerableTSource. When you use instance method syntax to call this method, omit the first parameter. For more information, see
Extension Methods (Visual Basic) or
Extension Methods (C# Programming Guide).
RemarksHere the word
substring is to be understood in the mathematical sense; it's not related to character strings. See the
definition on Wikipedia.
See Also