uniblab icon

better fix

uniblab | PRO | 09/07/18 04:22:48 PM UTC | 0 ⭐ | 1413 👁️ | Never ⏰ | []
C# |

720 B

|

None

|

0 👍

/

0 👎

public static System.String TrimToNull( this System.String @string ) {
    if ( System.String.IsNullOrEmpty( @string ) ) {
        return null;
    }
    @string = @string.Trim();
    return ( System.String.IsNullOrEmpty( @string ) )
        ? null
        : @string
    ;
}
public static System.String CommaListToSingleQuotedCommaList( System.String commaList ) {
    commaList = commaList.TrimToNull();
    return ( null == commaList )
        ? null
        : System.String.Join(
            ",",
            commaList.Split( new System.Char[ 1 ] { ',' },
            System.StringSplitOptions.RemoveEmptyEntries
        ).Select(
            x => !x.Contains( "'" )
                ? x
                : x.Contains( "''" )
                    ? x
                    : x.Replace( "'", "''" )
        ).Select(
            x => "'" + x.TrimToNull() + "'"
        ) )
    ;
}

Comments