Created
May 17, 2024 13:49
-
-
Save karenpayneoregon/12ded222c856e549f5df78388573908b to your computer and use it in GitHub Desktop.
Lower case first character in a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class StringExtensions | |
{ | |
public static string? FirstCharacterToLowerCase(this string? sender) | |
{ | |
if (!string.IsNullOrEmpty(sender) && char.IsUpper(sender[0])) | |
{ | |
return sender.Length == 1 ? | |
char.ToLower(sender[0]).ToString() : | |
$"{char.ToLower(sender[0])}{sender[1..]}"; | |
} | |
return sender; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is safe instead
And orginal still prints out as "hello".