469,266 Members | 2,014 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,266 developers. It's quick & easy.

C# removing single quote from string

karenRoss
Am I even close to right? I dont recall how many single quotes it takes to represent a single quote in a aspx.cs code behind page.
Expand|Select|Wrap|Line Numbers
  1.  if (firstname.Contains( " ' " ))
  2.         {
  3.             indexof = firstname.IndexOf(" '  ");
  4.             firstname.Insert(indexof + 1, " ' ");
  5.         }
  6.         if (lastname.Contains("''"))
  7.         {
  8.             indexof = lastname.IndexOf(" '  ");
  9.             lastname.Insert(indexof + 1, " '  ");
  10.         }
Jun 6 '07 #1
5 25096
Plater
7,872 Expert 4TB
Here's what I use:
Expand|Select|Wrap|Line Numbers
  1. private static string quoteReplace(string psString)
  2. {
  3.     return psString.Replace("'", "''");
  4. }
  5.  
That is replace a single quote ' with two single quotes ''
Jun 6 '07 #2
Here's what I use:
Expand|Select|Wrap|Line Numbers
  1. private static string quoteReplace(string psString)
  2. {
  3.     return psString.Replace("'", "''");
  4. }
  5.  
That is replace a single quote ' with two single quotes ''
I tried to use this however, when I step through the application the string is sent and it reads psString however, it does not actually make the change...rather just goes through the motions.
Jun 6 '07 #3
Plater
7,872 Expert 4TB
It is returning the changed string in the return value of the function, you either use the function as a function or do something like:

mysring= mystring.replace("'","''");
Jun 6 '07 #4
ignore this post...see below...
Jun 6 '07 #5
Nevermind, I'm an idiot.

I am obviously missing the ( variable = blah blah; )

and just had the blah blah...

Thanks for your help :-)
Jun 6 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

11 posts views Thread by gopal srinivasan | last post: by
6 posts views Thread by bruce | last post: by
3 posts views Thread by =?Utf-8?B?ai5hLiBoYXJyaW1hbg==?= | last post: by
13 posts views Thread by cront | last post: by
6 posts views Thread by Schroeder, AJ | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.