字符串变量奇怪的行为 [英] String variable strange behavior

查看:90
本文介绍了字符串变量奇怪的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在变量中有一些字符串str_tmp =" C:\ TMP \"

我想在文本框中显示它(@ -quoted),所以我正在使用tbx .Text =

@str_tmp;但由于一些奇怪的原因,这不起作用。它处理

转义序列。有什么问题???


-

Tamir Khason

我是谁?
http://www.khason.biz/

I have some string in variable str_tmp = "C:\TMP\"
I want to display it in textbox (@-quoted), so I''m using tbx.Text =
@str_tmp; but for some strange reason this does not work. it processes
escape sequence. What is the problem???

--
Tamir Khason
Who am I at
http://www.khason.biz/

推荐答案




您使用了错误的转义字符,在声明您的

var时使用它:

string srt_tmp = @" c:\ tmp" ;;

分配时不必使用它:

tbx.Text = @str_tmp;

你刚才这样做

tbx.Text = str_tmp;

干杯,


-

Ignacio Machin,

ignacio.machin AT dot.state.fl.us

佛罗里达州运输部


Tamir Khason < TA ********** @ tcon-NOSPAM.co.il>在消息中写道

新闻:OB ************** @ TK2MSFTNGP12.phx.gbl ...
Hi,

You are using incorrectly the escape char, use it when you declare your
var:
string srt_tmp = @"c:\tmp";
you don''t have to use it when you assign it:
tbx.Text = @str_tmp;
you just do
tbx.Text = str_tmp;
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:OB**************@TK2MSFTNGP12.phx.gbl...
我有一些字符串变量str_tmp =" C:\ TMP \"
我想在文本框中显示它(@ -quoted),所以我正在使用tbx.Text =
@str_tmp;但由于一些奇怪的原因,这不起作用。它处理转义序列。有什么问题???

-
Tamir Khason
我是谁?
http://www.khason.biz/
I have some string in variable str_tmp = "C:\TMP\"
I want to display it in textbox (@-quoted), so I''m using tbx.Text =
@str_tmp; but for some strange reason this does not work. it processes
escape sequence. What is the problem???

--
Tamir Khason
Who am I at
http://www.khason.biz/



Do没有帮助。

我有一个类似的结构:


public struct SomeStringStruct

{

public string A_String;

public SomeStringStruct(string a_string)

{

A_String = a_string;

}

}

现在我应该在哪里添加@以便能够接收@ -quoted字符串,例如。

SomeStringStruct a = new SomeStringStruct(" \\ \\ n \\ n \\ n \\ n \\ n\\ n)

Console.WriteLine(a.A_String); //应该返回\ n \ n \ n而不是< CR>< CR>< CR>


-

Tamir Khason

您想要dot.NET吗?只需询问:

"请, www.dotnet.us

Ignacio Machin(.NET / C#MVP)" < ignacio.machin AT dot.state.fl.us>在消息新闻中写了

:eu ************* @ TK2MSFTNGP11.phx.gbl ...
Do not helps.
I have a struct like:

public struct SomeStringStruct
{
public string A_String;
public SomeStringStruct(string a_string)
{
A_String = a_string;
}
}
Now where should I add @ in order to be able to recieve @-quoted strings eg.
SomeStringStruct a = new SomeStringStruct ("\n\n\n")
Console.WriteLine(a.A_String); // Should return \n\n\n and not <CR><CR><CR>

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:eu*************@TK2MSFTNGP11.phx.gbl...


你错误地使用了转义字符,当你声明你的字符串时使用它
var:
字符串srt_tmp = @" c:\ tmp" ;;
你不要必须在分配时使用它:
tbx.Text = @str_tmp;
你刚才做的
tbx.Text = str_tmp;

干杯,
-
Ignacio Machin,
ignacio.machin at dot.state.fl.us
佛罗里达州交通局

Tamir Khason < TA ********** @ tcon-NOSPAM.co.il>在消息中写道
新闻:OB ************** @ TK2MSFTNGP12.phx.gbl ...
Hi,

You are using incorrectly the escape char, use it when you declare your
var:
string srt_tmp = @"c:\tmp";
you don''t have to use it when you assign it:
tbx.Text = @str_tmp;
you just do
tbx.Text = str_tmp;
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:OB**************@TK2MSFTNGP12.phx.gbl...
我在变量str_tmp ="中有一些字符串; C:\ TMP \"
我想在文本框中显示它(@ -quoted),所以我正在使用tbx.Text =
@str_tmp;但由于一些奇怪的原因,这不起作用。它处理转义序列。有什么问题???

-
Tamir Khason
我是谁?
http://www.khason.biz/
I have some string in variable str_tmp = "C:\TMP\"
I want to display it in textbox (@-quoted), so I''m using tbx.Text =
@str_tmp; but for some strange reason this does not work. it processes
escape sequence. What is the problem???

--
Tamir Khason
Who am I at
http://www.khason.biz/




" Tamir Khason" < TA ********** @ tcon-NOSPAM.co.il>写道:
"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote:
现在我应该在哪里添加@以便能够收到@ -quoted字符串,例如。
SomeStringStruct a = new SomeStringStruct(" \\ \\ n \\\ n \\ nn \\;)
Console.WriteLine(a.A_String); //应该返回\ n \ n \\ n
而不是< CR>< CR>< CR>
Now where should I add @ in order to be able to
recieve @-quoted strings eg.
SomeStringStruct a = new SomeStringStruct ("\n\n\n")
Console.WriteLine(a.A_String); // Should return \n\n\n
and not <CR><CR><CR>




@只是对于源代码中的文字硬编码字符串非常有用。


如果要将不可打印的字符转换为文本

表示其转义序列(例如< CR>到''\ n''),你将需要自己进行替换,例如


string s2 = s1。替换(\ n,@" \ n"); // ...依此类推


P.



@ is only useful for literal hard-coded strings in your source code.

If you want to convert non-printable characters to the text
representation of their escape sequences (e.g. <CR> to ''\n''), you will
have to do the replacements yourself, e.g.

string s2 = s1.Replace("\n", @"\n"); // ... and so on

P.


这篇关于字符串变量奇怪的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆