/// <summary> /// Converts a string of the form 'There''s a double single quote in here' /// or, for unicode strings, N'There''s a double single quote in here' /// (including the optional N and the outer single quotes) to the string literal /// "There's a double single quote in here" (not including the double quotes). /// </summary> /// <param name="sqlServerStringLiteral"> the string to convert </param> /// <returns> the converted string, or null if it cannot convert </returns> public virtual string ConvertSqlServerStringLiteral([NotNull] string sqlServerStringLiteral) { Check.NotEmpty(sqlServerStringLiteral, nameof(sqlServerStringLiteral)); if (sqlServerStringLiteral[0] == 'N') { sqlServerStringLiteral = sqlServerStringLiteral.Substring(1); } var sqlServerStringLiteralLength = sqlServerStringLiteral.Length; if (sqlServerStringLiteralLength < 2) { Logger.LogWarning( SqlServerDesignStrings.CannotInterpretSqlServerStringLiteral(sqlServerStringLiteral)); return(null); } if (sqlServerStringLiteral[0] != '\'' || sqlServerStringLiteral[sqlServerStringLiteralLength - 1] != '\'') { Logger.LogWarning( SqlServerDesignStrings.CannotInterpretSqlServerStringLiteral(sqlServerStringLiteral)); return(null); } return(sqlServerStringLiteral.Substring(1, sqlServerStringLiteralLength - 2) .Replace("''", "'")); }