[英]How to remove escape characters from file path string in c#?
Ok, I feel like this is a really stupid basic question but I cannot find the answer. 好的,我觉得这是一个非常愚蠢的基本问题,但我找不到答案。
I am building a web service in c# and I am using MsgReader to read Outlook email files. 我正在C#中构建Web服务,并且正在使用MsgReader来读取Outlook电子邮件文件。 To open a message I use this line: 要打开一条消息,请使用以下行:
Storage.Message message = new Storage.Message(filePath);
filePath will be coming from a remote location and will be something like "c:\\apple.msg". filePath将来自远程位置,并且类似于“ c:\\ apple.msg”。 This does not work. 这是行不通的。 If I use "c:\\\\apple.msg" it works just fine. 如果我使用“ c:\\\\ apple.msg”,它就可以正常工作。
It is interpreting that as an escape character. 它将其解释为转义字符。 I tried String.Replace to change the \\ to \\\\ but the string is a null value before it can even get to that point. 我试过String.Replace来将\\更改为\\\\,但是在达到该值之前,该字符串是一个空值。 This seems like a very simple problem, because I enter file paths as command line arguments all the time. 这似乎是一个非常简单的问题,因为我一直都在输入文件路径作为命令行参数。 How do you do this? 你怎么做到这一点?
Additional info: The path will come from a web service call from a PHP application using SOAP. 附加信息:该路径将来自使用SOAP的PHP应用程序中的Web服务调用。 It dawned on me that I can replace the slash with double slashes before I make the call, but I would like to know how other people handle this problem. 我突然意识到,我可以在拨打电话之前用双斜杠替换斜杠,但是我想知道其他人如何处理这个问题。
嗯,尝试这样写路径:
string filepath = @"c:\apple.msg";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.