Skip to content

Commit

Permalink
Added string extensions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix-CodingClimber committed Apr 6, 2024
1 parent fd9b126 commit 19812c8
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/DotNetElements.Core/Core/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace DotNetElements.Core.Extensions;
public static class StringExtensions
{
public static string FirstNCharacters(this string str, int n)
{
if (string.IsNullOrEmpty(str) || str.Length <= n)
return str;

return str[..n];
}

public static string LastNCharacters(this string str, int n)
{
if (string.IsNullOrEmpty(str) || str.Length <= n)
return str;

return str.Substring(str.Length - n, n);
}
}

0 comments on commit 19812c8

Please sign in to comment.