zoukankan      html  css  js  c++  java
  • 从字符串中分离文件路径文件名及拓展

    实现效果:

    关键知识:(  用到了string对象的Substring()  LastIndexOf()   )

    实现代码:

     1         private void button1_Click(object sender, EventArgs e)
     2         {
     3             if (openFileDialog1.ShowDialog() == DialogResult.OK) {//判断选中
     4                 string File_all = openFileDialog1.FileName;//获取全部路径
     5                 string File_path =
     6                     File_all.Substring(0, File_all.LastIndexOf('\') + 1);//文件路径
     7                 string File_name =
     8                     File_all.Substring(File_all.LastIndexOf('\')+1
     9                     ,File_all.LastIndexOf('.')-1 - File_all.LastIndexOf('\'));//文件名
    10                 string File_exc =
    11                     File_all.Substring(File_all.LastIndexOf('.') + 1,
    12                     File_all.Length - File_all.LastIndexOf('.')-1);//文件拓展名
    13 
    14                 textBox1.Text = File_path;//显示路径
    15                 textBox2.Text = File_name;//显示文件名称
    16                 textBox3.Text = File_exc;//显示拓展名称
    17             }
    18         }
  • 相关阅读:
    A good habit is half done
    mysql 练习题
    管理的实践
    mysql 表关联时执行顺序
    python 实现短信轰炸
    python django码云第三方登录
    mysql事务的隔离级别
    微服务
    什么是git
    如何使用Hexo创建博客
  • 原文地址:https://www.cnblogs.com/feiyucha/p/9901567.html
Copyright © 2011-2022 走看看