• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 332
  • Last Modified:

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
0
dauve
Asked:
dauve
  • 2
  • 2
1 Solution
 
jkrCommented:
char* double_apostrophes ( const char* src, char* dst, unsigned dstsize) {

    unsigned count = 0;
    while ( *src && count < dstsize) {

    *dst = *src;

    if ( '\'' == *src) ++dst, *dst = *src;

    ++src;
    ++dst;
    ++count;
}
0
 
jonathan6587Commented:
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
0
 
jkrCommented:
Interesting. Is that different from my proposal? :o)
0
 
dauveAuthor Commented:
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
0
 
jonathan6587Commented:
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
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now