Is your feature request related to a problem? Please describe.
Since SQL Server 2022 LTRIM and RTRIM support a second argument characters to remove other characters than just spaces. TRIM needs a different syntax.
Describe the solution you'd like
At least for LTRIM AND RTRIM it should be fairly easy to support the additional argument and therefore allow trimming of arbitrary characters.
Describe alternatives you've considered
Alternatives are possible with a set of 4 REPLACEs or just doing it client side.
Additional context
I think this should work:
/// <summary>
/// Removes a set of characters from the start of a string
/// </summary>
/// <param name="expression">A character expression where characters should be removed</param>
/// <param name="characters">A set of characters to be removed from the stadt and end of <paramref name="expression"/></param>
/// <returns></returns>
[SqlFunction(IsDeterministic = true)]
public static SqlString LTrim([MaxLength] SqlString expression, SqlString characters)
{
if (expression.IsNull || characters.IsNull)
return SqlString.Null;
return new SqlString(expression.Value.TrimStart(characters.Value.ToCharArray()), expression.LCID, expression.SqlCompareOptions);
}
/// <summary>
/// Removes a set of characters from the end of a string
/// </summary>
/// <param name="expression">A character expression where characters should be removed</param>
/// <param name="characters">A set of characters to be removed from the stadt and end of <paramref name="expression"/></param>
/// <returns></returns>
[SqlFunction(IsDeterministic = true)]
public static SqlString RTrim([MaxLength] SqlString expression, SqlString characters)
{
if (expression.IsNull || characters.IsNull)
return SqlString.Null;
return new SqlString(expression.Value.TrimEnd(characters.Value.ToCharArray()), expression.LCID, expression.SqlCompareOptions);
}
Is your feature request related to a problem? Please describe.
Since SQL Server 2022 LTRIM and RTRIM support a second argument
charactersto remove other characters than just spaces. TRIM needs a different syntax.Describe the solution you'd like
At least for
LTRIMANDRTRIMit should be fairly easy to support the additional argument and therefore allow trimming of arbitrary characters.Describe alternatives you've considered
Alternatives are possible with a set of 4 REPLACEs or just doing it client side.
Additional context
I think this should work: