473,226 Members | 1,336 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,226 software developers and data experts.

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 26631
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

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

Similar topics

11
by: gopal srinivasan | last post by:
Hi, I have a text like this - "This is a message containing tabs and white spaces" Now this text contains tabs and white spaces. I want remove the tabs and white...
6
by: Niyazi | last post by:
Hi all, What is fastest way removing duplicated value from string array using vb.net? Here is what currently I am doing but the the array contains over 16000 items. And it just do it in 10 or...
6
by: bruce | last post by:
hi... i'm running into a problem where i'm seeing non-ascii chars in the parsing i'm doing. in looking through various docs, i can't find functions to remove/restrict strings to valid ascii...
11
by: cmay | last post by:
I am having this problem... Lets say that your source XML is formatted like this: <somenode> Here is some text Here is some more text </somenode> When to a <xsl:value-of select="somenode" /I...
8
by: starsky51 | last post by:
I'm sure it's something i'm doing wrong, I just can't see it. I've set up a simple page with the following code: <html> <head> <title>tester</title> <script language="javascript"...
3
by: =?Utf-8?B?ai5hLiBoYXJyaW1hbg==?= | last post by:
Hello, I've eliminated the bulk of code, this should be sufficient: byte fromEncrypt; string sDecryptedString; //Read the data out of the crypto stream. csDecrypt.Read(fromEncrypt, 0,...
5
by: tom.hepworth | last post by:
Hi I have a problem which I hope someone can help me with because I really don't even know where to start with it. I am using Access 2003. I have a delimited text file which contains about...
2
by: beatTheDevil | last post by:
Hey guys, As the title says I'm trying to make a regular expression (regex/regexp) for use in removing the comments from code. In this case, this particular regex is meant to match /* ... */...
13
by: cront | last post by:
I have a problem to work on: we will ask user to input anything and we will put that back onto the standard output with all set of brackets removed. We will not remove any single bracket e.g. ...
6
by: Schroeder, AJ | last post by:
Hello group, I am attempting to remove double quotes from the beginning and ending of a string. Admittedly, I am not the best with regular expressions, but I do have two that work with...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.