This should be faster. I'm not sure about the Insert method as far as performance goes but this method shouldn't cause any unneeded string allocations. However, I'm sure it could be improved on.
public static string DoQuotes(string sqlParam) { System.Text.StringBuilder sb = new System.Text.StringBuilder(sqlParam.Length + 2); if (sqlParam.IndexOf("'") > 0) { sb.Insert(2,sb.Replace("'", "''").ToString()); } else { sb.Insert(2, sqlParam); } sb.Insert(1, "'"); sb.Append("'"); return sb.ToString(); } Erick ----- Original Message ----- From: "Greg Gates" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, May 02, 2002 5:24 PM Subject: [DOTNET] String concatenation performance > Hello everyone: > > I have the following helper method to format sql string parameters: > > public static string DoQuotes(string sqlParam) > { > if (sqlParam.IndexOf("'") > 0) > { > sqlParam = sqlParam.Replace("'","''"); > } > > return "'" + sqlParam + "'"; > } > > > Is there a better way, performance-wise? > > thanks, Greg > > You can read messages from the DOTNET archive, unsubscribe from DOTNET, or > subscribe to other DevelopMentor lists at http://discuss.develop.com. You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.