C#基础 string Substring 从文件的全称中分出文件的类型与名字

  • .NET Framework : 4.7.2
  •        IDE : Visual Studio Community 2019
  •         OS : Windows 10 x64
  •     typesetting : Markdown
  •         blog : xinshaopu.blog.csdn.net

code

using System;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            string fullName = "CSharp2.2.txt";
            int index = fullName.LastIndexOf('.');
            string fileType = fullName.Substring(index + 1, fullName.Length - index - 1);
            Console.WriteLine("文件的类型是:" + fileType);
            string fileName = fullName.Substring(0, index);
            Console.WriteLine("文件名是:" + fileName);
            Console.ReadKey();

        }
    }
}

result

文件的类型是:txt
文件名是:CSharp2.2

more knowledge

  • 如果是类似于本地DNS文件 hosts, 它没有字符’.’,也没有后缀名。上面的程序就报错了。
    在这里插入图片描述

resource

  • [文档] docs.microsoft.com/zh-cn/dotnet/csharp
  • [规范] github.com/dotnet/docs/tree/master/docs/standard/design-guidelines
  • [源码] referencesource.microsoft.com
  • [平台] www.csdn.net
  • [ IDE ] visualstudio.microsoft.com/zh-hans
  • [.NET Core] dotnet.github.io


感恩曾经帮助过 心少朴 的人。
C#优秀,值得学习。.NET Core具有跨平台的能力,值得关注。
Console,WinForm,WPF,ASP.NET,Azure WebJob,WCF,Unity3d,UWP可以适当地了解。
注:此文是自学笔记所生,质量中下等,故要三思而后行。新手到此,不可照搬,应先研究其理象数,待能变通之时,自然跳出深坑。

欢迎关注微信公众号:悟为生心

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值