• Path类


     1 using System;
     2 using System.Collections.Generic;
     3 using System.IO;
     4 using System.Linq;
     5 using System.Text;
     6 using System.Threading.Tasks;
     7 
     8 namespace _14Path类
     9 {
    10     class Program
    11     {
    12         static void Main(string[] args)
    13         {
    14             string str = @"C:3000softRed SpiderDataMessage老赵.wav";
    15             //获得文件名
    16             Console.WriteLine(Path.GetFileName(str));
    17             //获得文件名但是不包含扩展名
    18             Console.WriteLine(Path.GetFileNameWithoutExtension(str));
    19             //获得文件的扩展名
    20             Console.WriteLine(Path.GetExtension(str));
    21             //获得文件所在的文件夹的名称
    22             Console.WriteLine(Path.GetDirectoryName(str));
    23             //获得文件所在的全路径
    24             Console.WriteLine(Path.GetFullPath(str));
    25             //连接两个字符串作为路径
    26             Console.WriteLine(Path.Combine(@"c:a" , "b.txt"));
    27 
    28            
    29             //int index = str.LastIndexOf("\");
    30             //str = str.Substring(index + 1);
    31             //Console.WriteLine(str);
    32             Console.ReadKey();
    33         }
    34     }
    35 }

    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
    博文来源广泛,如原作者认为我侵犯知识产权,请尽快给我发邮件 664507902@qq.com联系,我将以第一时间删除相关内容。

  • 相关阅读:
    每天一道算法题(13)——使用递归颠倒栈
    每天一道算法题(12)——和为n的连续正数序列或者随机数
    函数模板
    答题总结(1)
    顶点间最短路径长度之探寻算法
    最小生成树
    new与delete,malloc与free
    C++的继承与接口
    笔记13 AOP中After和AfterReturning的区别
    笔记12 注入AspectJ切面
  • 原文地址:https://www.cnblogs.com/ooip/p/4733590.html
  • Copyright © 2020-2023  润新知