C # obtain the relative path (absolute path to relative path ),
There are many methods for this.
1. Use PInvok to call the PathRelativePathTo of Windows API
2. Process strings by yourself
3. Use Uri
If you don't want to talk about the first two types, you may feel a little troublesome. If you want to know more about them, Baidu and Google.
3rd types, no easy to say, direct Code.
1 public static string GetRelativePath(string filespec, string folder) 2 { 3 const string directorySeparatorChar = "\\"; 4 Uri pathUri = new Uri(filespec); 5 6 if (!folder.EndsWith(directorySeparatorChar)) 7 { 8 folder += directorySeparatorChar; 9 }10 Uri folderUri = new Uri(folder);11 return Uri.UnescapeDataString(folderUri.MakeRelativeUri(pathUri).ToString().Replace("/", directorySeparatorChar));12 }
This is because it is used in WinRT. In WinRT, there is no Path. DirectorySeparatorChar. You should replace "\" with Path. DirectorySeparatorChar in other environments "\\".
& In C Language
& Can be used as the bitwise AND or address fetch Operator
The following describes two usage methods:
1. bitwise and operation bitwise AND operator "&" are binary operators. Its function is the binary phase corresponding to the two numbers involved in the operation. The result bit is 1 only when the two binary numbers are 1. Otherwise, the result bit is 0. The number of involved operations is supplemented.
For example, 9 & 5 can be written as follows: 00001001 (Binary complement of 9) & 00000101 (Binary complement of 5) 00000001 (Binary complement of 1) Visible 9 & 5 = 1.
Bitwise AND operations are usually used to clear some bits or retain some bits. For example, if a clears the high eight bits of 0 and retains the low eight bits, it can be used as a & 255 operation (255 of the binary number is 0000000011111111 ).
2. Get the address
& As The unary operator, the result is the address of the right operation object.
For example, & x returns the address of x.
The address itself is an abstract concept used to indicate the logical location of an object in the memory.
& In C Language
& Can be used as the bitwise AND or address fetch Operator
The following describes two usage methods:
1. bitwise and operation bitwise AND operator "&" are binary operators. Its function is the binary phase corresponding to the two numbers involved in the operation. The result bit is 1 only when the two binary numbers are 1. Otherwise, the result bit is 0. The number of involved operations is supplemented.
For example, 9 & 5 can be written as follows: 00001001 (Binary complement of 9) & 00000101 (Binary complement of 5) 00000001 (Binary complement of 1) Visible 9 & 5 = 1.
Bitwise AND operations are usually used to clear some bits or retain some bits. For example, if a clears the high eight bits of 0 and retains the low eight bits, it can be used as a & 255 operation (255 of the binary number is 0000000011111111 ).
2. Get the address
& As The unary operator, the result is the address of the right operation object.
For example, & x returns the address of x.
The address itself is an abstract concept used to indicate the logical location of an object in the memory.