I use something like this (I've cut two methods together to make it
easier to read.) It works, but maybe isn't the fastest way of doing it.
public static final String replaceSingleQuotes(String source){
char oldChar = '\'';
String newString = "''";
StringBuffer sb = new StringBuffer();
int len = source.length();
for(int i=0; i<len; i++){
if(source.charAt(i)==oldChar){
sb.append(newString);
}else{
sb.append(source.charAt(i));
}
}
return sb.toString();
}
Jeff Dillon wrote:
>
> Can anyone tell me of an easy way to replace a single quote in a string with
> two single quotes so that I don't get any SQL errors? I have tried:
>
> myString.replace('\'','\'\'');
>
> and
>
> Char single = '\'';
> Char double = single + single;
>
> myString .replace(single,doulble);
>
> but neither work for obvious reasons...
>
> Thanks for any help.
>
> Jeff Dillon
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html