Solved

Replace an Apostrophe

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

706 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

17 Experts available now in Live!

Get 1:1 Help Now