removing @ from string

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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.
 
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
 
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?
 
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
 
Back
Top