79395379

Date: 2025-01-28 23:03:56
Score: 1
Natty:
Report link

Building on @scott-jibben's idea of using Indices and ranges, and adding support for nulls and strings shorter than the desired max length, I arrived at the following extension method for LEFT:

public static string Left(this string myString, int maxLength)
{
    if (string.IsNullOrEmpty(myString)) return myString;
    return myString[..Math.Min(maxLength, myString.Length)];
}
Reasons:
  • Has code block (-0.5):
  • User mentioned (1): @scott-jibben's
  • Low reputation (0.5):
Posted by: ConfuedProblemSolver