c# 去除转义符号,如何忽略@转义字符(C#)

Hi,

I added a string property for my winforms control.

This string property can take multiple lines of text by using "\r\n".

For example, "Hello\r\nWorld"

SHOULD prints:

Hello

World

The problem is that c# _always_ treats my string as _path_ (using @-quoted).

It prints:

Hello\r\nWorld

I would like to get rid of this silly ''@'' in this case.

How do I correct this?

Thanks.

Minh

解决方案C# does not treat strings as "literals" unless they are constants, prefixed with the ''@'' character.

If your property is of type String, then your code must assume that the value passed in to the set accessor is already formatted

correctly. In other words, your code cannot determine whether the caller used the ''@'' symbol.

Do not set your property using the ''@'' character if you want to preserve the "\r\n" escape characters.

--

Dave Sexton

dave@www..jwaonline..com

-----------------------------------------------------------------------

"Newcomer" wrote in message news:21**************************@posting.google.c om...Hi,

I added a string property for my winforms control.

This string property can take multiple lines of text by using "\r\n".

For example, "Hello\r\nWorld"

SHOULD prints:

Hello

World

The problem is that c# _always_ treats my string as _path_ (using @-quoted).

It prints:

Hello\r\nWorld

I would like to get rid of this silly ''@'' in this case.

How do I correct this?

Thanks.

Minh

The problem is that c# _always_ treats my string as _path_ (using @-quoted).

It prints:

Hello\r\nWorld

Where do you print it? If you view the string in the debugger it may

appear that way.

Mattias

--

Mattias Sj?gren [MVP] mattias @ mvps.org

http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com

Please reply only to the newsgroup.

Dave, thanks for your reply.

I DON''T use ''@'' in the string property.

I think, this problem only happends when I tried to set the string value

at _design_time_. C# will detects "\r\n" and treats that as path.

You can test this by having a simple form with a text editor (textBox1).

At design time, set the text value (textBox1) to "Hello\r\nWorld"

(ignore the quotes). Then in your test code, try

Console.WriteLine(textBox1.Text).

You _will_ get just a single line of print out.

That is my problem.

Thanks again.

Ming

*** Sent via Developersdex http://www.developersdex.com ***

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值