二维码
微世推网

扫一扫关注

当前位置: 首页 » 企业商讯 » 商机资讯 » 正文

分离文件路径_名称和扩展名源代码

放大字体  缩小字体 发布日期:2021-10-31 08:54:11    作者:田喾弛    浏览次数:331
导读

分离文件路径、名称和扩展名源代码:程序界面using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace WindowsFormsApplica

分离文件路径、名称和扩展名源代码:

程序界面

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace WindowsFormsApplication2{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { //"E:\study\mydatabase\学生个人数据库.accdb" if (openFileDialog1.ShowDialog()==DialogResult.OK) { string f_all = openFileDialog1.FileName; string f_path = f_all.Substring(0, f_all.LastIndexOf("\\") + 1); string f_name = f_all.Substring(f_all.LastIndexOf("\\") + 1, f_all.LastIndexOf(".") - (f_all.LastIndexOf("\\") + 1)); string f_ex = f_all.Substring(f_all.LastIndexOf(".") + 1, f_all.Length - (f_all.LastIndexOf(".") + 1)); label1.Text = "文件路径:" + f_path; label2.Text = "文件名:" + f_name; label3.Text = "扩展名:" + f_ex; } } }}结语:学会使用打开对话框控件openFileDialog和截取字符串方法Substring和获取特定字符索引号IndexOf(正序)和LastIndexOf(倒序),喜欢得请收藏!

 
(文/田喾弛)
免责声明
• 
本文仅代表发布者:田喾弛个人观点,本站未对其内容进行核实,请读者仅做参考,如若文中涉及有违公德、触犯法律的内容,一经发现,立即删除,需自行承担相应责任。涉及到版权或其他问题,请及时联系我们删除处理邮件:weilaitui@qq.com。
 

Copyright©2015-2025 粤公网安备 44030702000869号

粤ICP备16078936号

微信

关注
微信

微信二维码

WAP二维码

客服

联系
客服

联系客服:

24在线QQ: 770665880

客服电话: 020-82301567

E_mail邮箱: weilaitui@qq.com

微信公众号: weishitui

韩瑞 小英 张泽

工作时间:

周一至周五: 08:00 - 24:00

反馈

用户
反馈