Skip to content

Commit

Permalink
capitalize letters by index
Browse files Browse the repository at this point in the history
  • Loading branch information
JerryImMouse committed Jun 27, 2024
1 parent 0a14710 commit 1ea6dbe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Jerry.Utilities/HttpUtility/HttpContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private void ParseHttpMethod()

method = method
.ToLower()
.CapitalizeFirstLetter();
.CapitalizeLetter(0);

if (!Enum.TryParse(method, out Method parsedMethod))
HttpMethod = Method.Get;
Expand Down
6 changes: 4 additions & 2 deletions Jerry.Utilities/Utility/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ namespace Jerry.Utilities.Utility;

public static class StringExtensions
{
public static string CapitalizeFirstLetter(this string str)
public static string CapitalizeLetter(this string str, int letterIndex)
{
if (str.Length == 0)
throw new NullReferenceException("String is null");

ArgumentOutOfRangeException.ThrowIfGreaterThan(letterIndex, str.Length - 1);

var array = str.ToCharArray();
array[0] = char.ToUpper(array[0]);
array[letterIndex] = char.ToUpper(array[letterIndex]);
return new string(array);
}
}

0 comments on commit 1ea6dbe

Please sign in to comment.