How can I convert c:\foo\\..\bar
into c:\bar
?
Two ways : string sRaw = "5.32"; string sClean = sRaw. Replace(".", ""); Trim is make for removing leading and trailings characters (such as space by default).
(dot dot) This refers to the parent directory of your working directory, immediately above your working directory in the file system structure. If one of these is used as the first element in a relative path name, it refers to your working directory.
A relative path refers to a location that is relative to a current directory. Relative paths make use of two special symbols, a dot (.) and a double-dot (..), which translate into the current directory and the parent directory. Double dots are used for moving up in the hierarchy.
C# tutorial is a comprehensive tutorial on C# language. The Path is located in the System.IO namespace. With the Path class, we can easily figure out the root path, the directory name of the file, its extension or create a random file name.
string path = Path.GetFullPath("C:\\foo\\..\\bar"); // path = "C:\\bar"
More Info
Have you tried
string path = Path.GetFullPath(@"C:\foo\..\bar");
in C# using the System.IO.Path class?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With