Today I had the need of
System.String.StartsWith
, but I wanted to specify whether or not to be case insensitive. There
is an overload that takes a value of
System.StringComparison
, but my method was already taking a
System.StringComparer
as a parameter, so it made more sense to use that. Here is what I devised:
namespace PIEBALD.Lib.LibExt.StartsWith
{
public static partial class LibExt
{
public static bool
StartsWith
(
this string String1
,
string String2
,
System.StringComparer Comparer
)
{
return
(
( String1.Length >= String2.Length )
&&
( Comparer.Compare ( String1.Substring ( 0 , String2.Length ) , String2 ) == 0 )
) ;
}
}
}
Edit: I changed it to use
System.Collections.Generic.IEqualityComparer<string>
.