Advertisement
uniblab

better fix

Sep 7th, 2018
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1. public static System.String TrimToNull( this System.String @string ) {
  2.     if ( System.String.IsNullOrEmpty( @string ) ) {
  3.         return null;
  4.     }
  5.     @string = @string.Trim();
  6.     return ( System.String.IsNullOrEmpty( @string ) )
  7.         ? null
  8.         : @string
  9.     ;
  10. }
  11. public static System.String CommaListToSingleQuotedCommaList( System.String commaList ) {
  12.     commaList = commaList.TrimToNull();
  13.     return ( null == commaList )
  14.         ? null
  15.         : System.String.Join(
  16.             ",",
  17.             commaList.Split( new System.Char[ 1 ] { ',' },
  18.             System.StringSplitOptions.RemoveEmptyEntries
  19.         ).Select(
  20.             x => !x.Contains( "'" )
  21.                 ? x
  22.                 : x.Contains( "''" )
  23.                     ? x
  24.                     : x.Replace( "'", "''" )
  25.         ).Select(
  26.             x => "'" + x.TrimToNull() + "'"
  27.         ) )
  28.     ;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement