Click or drag to resize

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
Syntax
public static int IndexOfSubstring<TSource>(
	this IEnumerable<TSource> source,
	IEnumerable<TSource> substring,
	IEqualityComparer<TSource>? comparer = null
)

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: Int32
The 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).
Remarks
Here 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