未核对的转义序列

编程入门 行业动态 更新时间:2024-10-14 10:44:41
本文介绍了未核对的转义序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

好吧,从这里开始是代码

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")

更多推荐

未核对的转义序列

本文发布于:2023-10-08 15:08:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1472986.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:序列

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!