Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions PowerKit.Tests/StringExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,14 @@ public void ToSnakeCase_Test()
"hello".ToSnakeCase().Should().Be("hello");
"".ToSnakeCase().Should().Be("");
}

[Fact]
public void Reverse_Test()
{
// Act & assert
"hello".Reverse().Should().Be("olleh");
"abcde".Reverse().Should().Be("edcba");
"a".Reverse().Should().Be("a");
"".Reverse().Should().Be("");
}
}
10 changes: 10 additions & 0 deletions PowerKit/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,15 @@ public string SeparateWords(char separator)
/// Converts the PascalCase string to snake_case (e.g., "FooBar" → "foo_bar").
/// </summary>
public string ToSnakeCase() => str.SeparateWords('_').ToLowerInvariant();

/// <summary>
/// Returns the string with the characters in reverse order.
/// </summary>
public string Reverse()
{
var chars = str.ToCharArray();
Array.Reverse(chars);
return new string(chars);
Comment thread
Tyrrrz marked this conversation as resolved.
Outdated
}
}
}