473,412 Members | 2,087 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,412 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 26709
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.