Link to home
Start Free TrialLog in
Avatar of dauve
dauve

asked on

Replace an Apostrophe

I am sending a sql statement that is doin an insert - the values that are going into the table come from another query and therefore come as: john's - I need to double up the qoutes and can't simply do a john''s or a john\'\'s.

Given a string with one apostrophe I need to replace it with two apostrophes.

Programming in C (pro*c).

Thanks
Dave
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Have you tried this.  

>>Given a string with one apostrophe I need to replace it with two apostrophes.


for( i = 0; i < strlen( string1 ); i++, j++ )
{
   string2[j] = string1[i];
   if( string1[i] == '\'';
   {
       j++;
       string2[j] = '\'';
    }
    string2[j+1] = '\0';
}

Hope this helps.

Jonathan
Interesting. Is that different from my proposal? :o)
Avatar of dauve
dauve

ASKER

I had already used the first answer and just didnt get a chance to get back to it - if the admin reads this he can take 50 points from me and give them to "jonathan6587" - I should have responded earlier.

Thanks for the help,
Dave
jkr.  

    Sorry.  I thought maybe my answer was a little more straight forward.  But NO it isn't really any different functionally.  Some people get confused when trying to work with other peoples functions, but in the end that is what DAVE would have needed.

Jonathan