将符号\赋值给字符串变量。 [英] Give a value with the sign \ to a string variable.

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

问题描述

你好!

我想给一个带有符号\的值给一个字符串变量。

问题是程序总是先添加符号@变量。

下一行给了我:@Name\shai


string str =" Name \\shai";


我想要str只是:Name\shai 。

我该怎么办?

提前致谢。

Hello!
I want to give a value with the sign \ to a string variable.
The problem is that the program always add the sign @ before the variable.
The next line gives me : @"Name\shai"

string str = "Name\\shai";

I want str to be only: "Name\shai" .
How can I do it?
Thanks in advance.

推荐答案

Niron kag写道:
Niron kag wrote:
你好!
我想给一个带有符号\的值给一个字符串变量。
问题是程序总是在变量前添加符号@ 。
下一行给了我:@Name\shai

string str =" Name \\shai;

我想要str仅为:Name\shai 。
我该怎么办?
提前致谢。
Hello!
I want to give a value with the sign \ to a string variable.
The problem is that the program always add the sign @ before the variable.
The next line gives me : @"Name\shai"

string str = "Name\\shai";

I want str to be only: "Name\shai" .
How can I do it?
Thanks in advance.




字符串前面的@只表示它是字面值,而且''\''是
不是转义字符。 " Name\\shai" == @" Name\sahi"

Dan Manges



The @ before the string just means it''s a literal value and that ''\'' is
not an escape character. "Name\\shai" == @"Name\sahi"
Dan Manges


你看到的并不总是你所得到的;


如果调试器显示@" Name\shai"或者Name \\shai,然后这个*就是*

你想要的字符串; \\和@只是告诉你(作为一个
的开发人员,而不是用户)字符串是如何被可视化的;它没有改变

实际内容。


如果你把字符串输出到屏幕或文件,或者其他什么,那么它

应显示为Name\shai


Marc
What you see is not always what you get;

If the debugger is displaying @"Name\shai" or "Name\\shai", then this *is*
the string you want; the \\ and @ are just there to tell you (as a
developer, not a user) how the string is being visualised; it doesn''t change
the actual contents.

If you output the string onto the screen or a file, or whatever, then it
should appear as "Name\shai"

Marc


您好,Niron!

Nk> string str =" Name \\shai" ;;


上面给你Name.\\Shai,


\ - 是特殊字符,为了在字符串中看到它你应该用另一个\符号来逃避它。


你可以用简单的控制台应用程序测试它:


string str =" test1 \ \ test2" ;;

Console.WriteLine(str);

string str1 =" test3 \\\\test4";

Console.WriteLine(str1);


-

问候,Vadym Stetsyak

www: http://vadmyst.blogspot.com


这篇关于将符号\赋值给字符串变量。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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