/// <summary> /// Determines whether the beginning of the <paramref name="span"/> matches the specified <paramref name="value"/> when compared using the specified <paramref name="comparisonType"/> option. /// </summary> /// <param name="span">The source span.</param> /// <param name="value">The sequence to compare to the beginning of the source span.</param> /// <param name="comparisonType">One of the enumeration values that determines how the <paramref name="span"/> and <paramref name="value"/> are compared.</param> public static bool StartsWith(this ReadOnlySpan <char> span, ReadOnlySpan <char> value, StringComparison comparisonType) { string.CheckStringComparison(comparisonType); switch (comparisonType) { case StringComparison.CurrentCulture: case StringComparison.CurrentCultureIgnoreCase: return(CultureInfo.CurrentCulture.CompareInfo.IsPrefix(span, value, string.GetCaseCompareOfComparisonCulture(comparisonType))); case StringComparison.InvariantCulture: case StringComparison.InvariantCultureIgnoreCase: return(CompareInfo.Invariant.IsPrefix(span, value, string.GetCaseCompareOfComparisonCulture(comparisonType))); case StringComparison.Ordinal: return(span.StartsWith(value)); default: Debug.Assert(comparisonType == StringComparison.OrdinalIgnoreCase); return(span.StartsWithOrdinalIgnoreCase(value)); } }