Solved

Replace an Apostrophe

Posted on 2003-11-25
5
325 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now