1、 用c#写一个程序关于利用字符串知识实现功能:分解出盘符、文件夹、文件名(不带后缀)、文件后缀
时间: 2023-07-10 18:33:20 浏览: 49
好的,我来给您编写一个示例程序,实现您所要求的功能:
```csharp
using System;
namespace StringManipulation
{
class Program
{
static void Main(string[] args)
{
string filePath = @"C:\Users\Administrator\Desktop\example.txt"; // 例子文件路径
string fileName = System.IO.Path.GetFileNameWithoutExtension(filePath); // 获取文件名(不带后缀)
string fileExtension = System.IO.Path.GetExtension(filePath); // 获取文件后缀
string directory = System.IO.Path.GetDirectoryName(filePath); // 获取文件夹路径
string drive = System.IO.Path.GetPathRoot(filePath); // 获取盘符
Console.WriteLine("盘符:{0}", drive);
Console.WriteLine("文件夹:{0}", directory);
Console.WriteLine("文件名:{0}", fileName);
Console.WriteLine("文件后缀:{0}", fileExtension);
Console.ReadLine();
}
}
}
```
您可以将 `filePath` 变量替换为您所需要处理的文件路径,运行程序即可得到分解出的盘符、文件夹、文件名和文件后缀。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)