Greg, IMHO, your code is pretty efficient. Using a StringBuilder might give you a marginal performance benefit, but it wouldn't be noticeable unless you intend to call this 10's of 1000's of times. It wouldn't hurt to use one, but it would only save you one string creation operation, and only in the case where there are one or more single quotes in the input string.
OTOH, your function has a bug: Your comparison should be >= 0. IndexOf returns -1 if not found, 0 if found in the first character position. Bill On Thu, 2 May 2002 17:24:18 -0700, Greg Gates <[EMAIL PROTECTED]> wrote: >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.