Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions csharp/Platform.Collections.Tests/StringTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,20 @@ public static void TrimSingleTest()
Assert.Equal("hello", "hello'".TrimSingle('\''));
Assert.Equal("hello", "'hello".TrimSingle('\''));
}

[Fact]
public static void EqualsIgnoreCaseTest()
{
Assert.True("Hello".EqualsIgnoreCase("hello"));
Assert.True("HELLO".EqualsIgnoreCase("hello"));
Assert.True("hello".EqualsIgnoreCase("HELLO"));
Assert.True("Hello World".EqualsIgnoreCase("HELLO WORLD"));
Assert.True("".EqualsIgnoreCase(""));
Assert.False("Hello".EqualsIgnoreCase("World"));
Assert.False("Hello".EqualsIgnoreCase("Hell"));
Assert.False("Hello".EqualsIgnoreCase(null!));
Assert.False(((string?)null).EqualsIgnoreCase("Hello"));
Assert.True(((string?)null).EqualsIgnoreCase(null));
}
}
}
21 changes: 21 additions & 0 deletions csharp/Platform.Collections/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,27 @@ public static string CapitalizeFirstLetter(this string @string)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string Truncate(this string @string, int maxLength) => string.IsNullOrEmpty(@string) ? @string : @string.Substring(0, Math.Min(@string.Length, maxLength));

/// <summary>
/// <para>
/// Determines whether the specified string equals another string ignoring case.
/// </para>
/// <para></para>
/// </summary>
/// <param name="@string">
/// <para>The string.</para>
/// <para></para>
/// </param>
/// <param name="other">
/// <para>The other string to compare with.</para>
/// <para></para>
/// </param>
/// <returns>
/// <para>True if the strings are equal ignoring case; otherwise, false.</para>
/// <para></para>
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool EqualsIgnoreCase(this string @string, string other) => string.Equals(@string, other, StringComparison.OrdinalIgnoreCase);

/// <summary>
/// <para>
/// Trims the single using the specified string.
Expand Down
Loading