为什么在再次使用字符串时会出现额外的字符 [英] Why extra charcter coming while using the string again

查看:57
本文介绍了为什么在再次使用字符串时会出现额外的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Windows应用程序中,我从用户那里获取服务器名称并将其存储在一个字符串中(比如说a)。在连接字符串中使用此字符串当我在调试模式下执行时,'\'字符即将出现

是什么原因?

这里我在执行时使用服务器名称为ADMIN \SQLEXPRESS

,服务器名称显示值为ADMIN \\SQLEXPRESS

请帮帮我

解决方案

因为在字符串文字中,反斜杠必须被转义,就是你写



  string  path =   ADMIN \\SQLEXPRESS; 





ADMIN \SQLEXPRESS 分配给变量路径。请参阅MSDN上的转义序列 [ ^ ]


你说:当我执行时在调试模式下

这听起来像问题是当你在调试器中查看值时。

如果是这种情况,则没有实际问题,它只是调试器在显示字符串值时添加额外反斜杠。



所以如果你有一个实际包含的字符串: ADMIN \SQLEXPRESS

调试器将显示为: ADMIN \ \SQLEXPRESS

In my windows application, i am getting the server name from the user and stores it in a string(say a).while using this string in connection string extra '\' character is coming when i am executing in debug mode
whats the reason?
here i used the server name as ADMIN\SQLEXPRESS
while executing, the server name is shows the value as ADMIN\\SQLEXPRESS
Please help me

解决方案

Because, inside a string literal, the backslash must be escaped, that is you write

string path = "ADMIN\\SQLEXPRESS";



to assign ADMIN\SQLEXPRESS to variable path. See "Escape Sequences" at MSDN[^]


You said: "when i am executing in debug mode"
That sounds like the issue is when you are looking at the value in the debugger.
If that is the case, then there is no actual problem, it is just that the debugger adds the extra backslash when it is displaying the string value.

So if you have a string that actually contains: ADMIN\SQLEXPRESS
The debugger will display this as: ADMIN\\SQLEXPRESS


这篇关于为什么在再次使用字符串时会出现额外的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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