how to remove " character from string in c#?

  • Thread starter Thread starter Milsnips
  • Start date Start date
M

Milsnips

Hi there,

i've tried the following:

string s = myString.Replace(""","");... but the compiler just doesnt like
it.
So, if there is a " in the string of text, i'd like to remove it.

any help appreciated.
thanks,
Paul
 
If you are using C# the following is what you would need to do:

string s = myString.Replace("\"","");

It requires an escape to recognize the quote.

Cheers!

Rob
 
The other way to escape characters is the @ symbol.

For example from http://www.softsteel.co.uk/tutorials/cSharp/lesson4.html
The second approach is to use 'verbatim string'
literals. These are defined by enclosing the required
string in the characters @" and ". To illustrate this,
to set the variable 'path' to the following value:
C:\My Documents\
we could either escape the back-slash characters
string path = "C:\\My Documents\\"
or use a verbatim string thus:
string path = @"C:\MyDocuments\"

Good luck,

JDK



Milsnips wrote:

aah yes thats it - the backslash was missing!
15-Mar-07

aah yes thats it - the backslash was missing! thanks
Paul

Previous Posts In This Thread:

how to remove " character from string in c#?
Hi there

i've tried the following

string s = myString.Replace(""","");... but the compiler just doesnt like
it
So, if there is a " in the string of text, i'd like to remove it

any help appreciated
thanks
Paul

Re: how to remove " character from string in c#?
string s = myString.Replace("\"","")

VJ

RE: how to remove " character from string in c#?
If you are using C# the following is what you would need to do

string s = myString.Replace("\"","")

It requires an escape to recognize the quote

Cheers

Ro

:

aah yes thats it - the backslash was missing!
aah yes thats it - the backslash was missing! thanks
Paul


Submitted via EggHeadCafe - Software Developer Portal of Choice
WPF Report Engine, Part 2
http://www.eggheadcafe.com/tutorial...c9-cf3a9ee210a7/wpf-report-engine-part-2.aspx
 
While the @ works often apparently the double qoutes is not a character that can be escaped that way. Apparently they call it a verbatim string.



Jay Kuykendall wrote:

Escaping characters
07-Apr-10

The other way to escape characters is the @ symbol.

For example from http://www.softsteel.co.uk/tutorials/cSharp/lesson4.html
The second approach is to use 'verbatim string'
literals. These are defined by enclosing the required
string in the characters @" and ". To illustrate this,
to set the variable 'path' to the following value:
C:\My Documents\
we could either escape the back-slash characters
string path = "C:\\My Documents\\"
or use a verbatim string thus:
string path = @"C:\MyDocuments\"

Good luck,

JDK

Previous Posts In This Thread:


Submitted via EggHeadCafe - Software Developer Portal of Choice
BizTalk Repeating Structures Table Looping and Table Extract
http://www.eggheadcafe.com/tutorial...0-a5704fe31a76/biztalk-repeating-structu.aspx
 
Jay said:
While the @ works often apparently the double qoutes is not a character that can be escaped that way. Apparently they call it a verbatim string.

I have no idea why you are responding to a message three YEARS old.

But, given that you are, you may be interested to know:

• Use of the @ isn't "escaping"; it's simply "verbatim", as you've heard
• If you want a double-quote character in a verbatim character, you
simply double it: @"She said ""Hello world!"" to the world"
 
Back
Top