Solved

Replace an Apostrophe

Posted on 2003-11-25
5
326 Views
Last Modified: 2010-04-15
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
Comment
Question by:dauve
  • 2
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
ID: 9820183
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
 
LVL 1

Expert Comment

by:jonathan6587
ID: 9850384
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
 
LVL 86

Expert Comment

by:jkr
ID: 9850628
Interesting. Is that different from my proposal? :o)
0
 

Author Comment

by:dauve
ID: 9851186
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
 
LVL 1

Expert Comment

by:jonathan6587
ID: 9858081
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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
port mapped I/o query 10 185
Parsing XML instructions in Java/any other language.... 3 110
Grammars for C C++ and java 1 122
Using popen() and gunzip() to open file in HTTPServer 6 59
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question