Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我收到一个类似“c:\test\abc.xlsx”的字符串,它指示我的 excel 路径。我必须依赖于我收到的内容并且不能对其进行硬编码。现在我应该如何确保单个“\”被转义并变成“\”
string **PATH** = "c:\test\abc.xlsx" string conn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=**PATH**;Extended Properties=Excel 12.0;";
单个“\”似乎没有正确转义。
尝试:string path = @"c:\test\abc.xlsx";
string path = @"c:\test\abc.xlsx";
前导 @ 符号将为您正确转义
应该很简单:
String thePath = "c:\\test\\abc.xlsx" String conn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + thePath + ";Extended Properties=Excel 12.0;";