Using C#, I need to prepare a search text for searching in a SQL Server database using the LIKE command by replacing all whitespace outside quotes with a % character. Exampl
Would have done something like this:
private static string RemoveUnquotedWhiteSpaces(string text)
{
string result = String.Empty;
var parts = text.Split('"');
for(int i = 0; i < parts.Length; i++)
{
if (i % 2 == 0) result += Regex.Replace(parts[i], " ", "");
else result += String.Format("\"{0}\"", parts[i]);
}
return result
}