removing @ from string

G

Guest

Hello
Is there a way to remove the @ that makes the string ignore escape characters

I have code like
string strTemp = this.TextBox1.Text

I type "hello\r\nWorld!" into TextBox1. The problem is it then forces strTemp to have the @ and ignores the escape characters. I want to keep the escape characters

Thanks for any ideas
Mar
 
M

Michael A. Covington

The @ is not part of the string. @"abc" and "abc" are the very same
string. The value of a string variable doesn't "have" the @.

Mark said:
Hello,
Is there a way to remove the @ that makes the string ignore escape characters?

I have code like:
string strTemp = this.TextBox1.Text;

I type "hello\r\nWorld!" into TextBox1. The problem is it then forces
strTemp to have the @ and ignores the escape characters. I want to keep the
escape characters.
 
G

Guest

Hell
Okay, I see how my last post could have been misinterpretted. I know that the @ is not part of the string

While "abc" and @"abc" may be the same string, "ab\nc" and @"ab\nc" do not act the same - the @ makes the "\" no longer act as an escape sequence

If I have a string like @"ab\nc", is there anyway I can make it like "ab\nc" (i.e. effectively remove the @), where the "\n" becomes an escape sequence

Thanks
Mar
Is there a way to remove the @ that makes the string ignore escap
characters


----- Michael A. Covington wrote: ----

The @ is not part of the string. @"abc" and "abc" are the very sam
string. The value of a string variable doesn't "have" the @

Mark said:
Hello
Is there a way to remove the @ that makes the string ignore escap characters
string strTemp = this.TextBox1.Text
strTemp to have the @ and ignores the escape characters. I want to keep th
escape characters
 
C

Chris A. R.

This will do what you're looking for:

using System.Text.RegularExpressions;

string testText = @"ab\nc";
string outText = Regex.Unescape( testText );
Debug.WriteLine( outText );

Chris A.R.


Mark said:
Hello
Okay, I see how my last post could have been misinterpretted. I know
that the @ is not part of the string.
While "abc" and @"abc" may be the same string, "ab\nc" and @"ab\nc" do not
act the same - the @ makes the "\" no longer act as an escape sequence.
If I have a string like @"ab\nc", is there anyway I can make it like
"ab\nc" (i.e. effectively remove the @), where the "\n" becomes an escape
sequence?
 
G

Guest

Thanks, exactly what I was looking for

Mar

----- Chris A. R. wrote: ----

This will do what you're looking for

using System.Text.RegularExpressions

string testText = @"ab\nc"
string outText = Regex.Unescape( testText )
Debug.WriteLine( outText )

Chris A.R


Mark said:
Hell
Okay, I see how my last post could have been misinterpretted. I kno
that the @ is not part of the string"ab\nc" (i.e. effectively remove the @), where the "\n" becomes an escap
sequence
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top