i've gotten habit of putting trailing slash @ end of folder paths , appears norm (e.g. visual studio macros such $(projectdir) have trailing slash). in addition, when i'm appending relative path end of existing folder path put leading slash in case folder path passed me doesn't have trailing slash (e.g. windows batch: set full_file_path=%folder_path%\path\to\some\file).
that being said, tend end paths c:\path\to\folder\\path\to\some\file.txt (note 2 backslashes in row). in addition, since i'm using dev\src dev\include , dev\script folder structure (where .vcxproj files , similar go in script folder), of paths append relative path up-levels @ end of macro $(projectdir) (e.g. include dir = $(projectdir)\..\include\).
in following code somepath02uri , somepath03uri return (what believe be) incorrect results:
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; namespace dotnet45systemuritest { class program { static void main(string[] args) { console.writeline("we test system.uri constructor:\n"); // output console.writeline in comment on same line string somepath01 = "c:\\some\\common\\..\\include\\"; console.writeline("somepath01 = " + somepath01); // somepath01 = c:\some\common\..\include\ uri somepath01uri = new uri(somepath01); console.writeline("somepath01uri = " + somepath01uri.tostring()); // somepath01uri = file:///c:/some/include/ console.writeline(); string somepath02 = "c:\\some\\common\\\\..\\include\\"; console.writeline("somepath02 = " + somepath02); // somepath02 = c:\some\common\\..\include\ uri somepath02uri = new uri(somepath02); console.writeline("somepath02uri = " + somepath02uri.tostring()); // somepath02uri = file:///c:/some/common/include/ console.writeline(); string somepath03 = "c:\\some\\common\\\\\\..\\include\\"; console.writeline("somepath03 = " + somepath03); // somepath03 = c:\some\common\\\..\include\ uri somepath03uri = new uri(somepath03); console.writeline("somepath03uri = " + somepath03uri.tostring()); // somepath03uri = file:///c:/some/common//include/ console.writeline(); } } } why system.uri interpret 2 slashes in row folder?
almost forgot: if encounter quick , dirty solution remove 2 backslashes in row string before creating uri object. did adding .replace("\\\\", "\\"):
string somepath02 = "c:\\some\\common\\\\..\\include\\"; console.writeline("somepath02 = " + somepath02); // somepath02 = c:\some\common\\..\include\ uri somepath02uri = new uri(somepath02.replace("\\\\", "\\")); console.writeline("somepath02uri = " + somepath02uri.tostring()); // somepath02uri = file:///c:/some/include/
the 2 slashes ar used non escaping.
for example try this:
string path = "c:\test\html";
when compile piece of code error "unrecognized escape sequence".
but if add slash, tell complier there no escaping intended , string should parsed is.
string path = "c:\\test\\html";
another intresting method non escaping is:
string path = @"c:\test\html";
Comments
Post a Comment