未核对的转义序列 [英] Unreconized escape sequence

查看:102
本文介绍了未核对的转义序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,从这里开始是代码

Well, to start with here is the code

config.Set("Silk", txt_silkdir.Text+"\silkroad.exe")



导致UNRECONIZED ESCAPE SEQUENCE错误的原因是"\ silkroad.exe"之类的部分

问题是我需要文件名带有\开头,因为我不知道如何在文件夹中添加尾随\\ BrowserDialog selectePath



And the thing cause the UNRECONIZED ESCAPE SEQUENCE error is the part were it is like "\silkroad.exe"

The thing is i need it to have the \ infront of the filename because i do not know how to add a trailing \ to the folderBrowserDialog selectePath

Any help would be apreciated.

推荐答案

使用@或\转义序列字符.

config.Set("Silk", txt_silkdir.Text+ @"\silkroad.exe")



config.Set("Silk", txt_silkdir.Text+ "\\silkroad.exe")
Use the @ or \ escape sequence character.

config.Set("Silk", txt_silkdir.Text+ @"\silkroad.exe")

OR

config.Set("Silk", txt_silkdir.Text+ "\\silkroad.exe")


在普通的C#字符串中,"\"字符引入了转义序列-一种将字符放入您不能键入的字符串中的方法(例如,换行符:"\ n")或字符串语法的一部分(ee双引号"\"'').
有两种解决方法:
1)在字符串前面加上一个"@"字符,在这种情况下,"\"将不再是转义序列介绍符.
In a normal C# string, the ''\'' character introduces an Escape Sequence - a way of getting characters into a string that you either can''t type (e.g. Newline: ''\n'') or which are part of the string syntax (e.e. double quotes ''\"'').
There are two ways around this:
1) Prefix your string with a ''@'' charcater, in which case ''\'' ceases to be an escape sequence introducer.
config.Set("Silk", txt_silkdir.Text+@"\silkroad.exe")




2)使用转义序列"\\"代替,它会在字符串中产生单个"\".


or

2) Use the escape squence ''\\'' instead which produces a single ''\'' as part of your string.

config.Set("Silk", txt_silkdir.Text+"\\silkroad.exe")


这篇关于未核对的转义序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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