public override string ToString() { if (string.IsNullOrWhiteSpace(InputScript)) { return(string.Empty); } if (InputScript.ToUpper().Contains("EXEC")) { return(InputScript); } // Check for a new line in the script int lastSelect = InputScript.LastIndexOf("SELECT", StringComparison.Ordinal); // if there is no new line, return the whole input script if (lastSelect == -1) { return(InputScript); } var finalSelect = InputScript.Substring(lastSelect); Regex trimmer = new Regex(@"\s\s+"); return(trimmer.Replace(finalSelect, " ")); // else }