一:从字符串总分离文件路径、命名、扩展名,上图

二:代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace FilePathString
{
public partial class Frm_Main : Form
{
public Frm_Main()
{
InitializeComponent();
} private void btn_Openfile_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)//判断是否选择了文件
{
string P_str_all = openFileDialog1.FileName;//记录选择的文件全路径
string P_str_path = //获取文件路径
P_str_all.Substring(, P_str_all.LastIndexOf("\\") + );//从最后一个/开始---到从最后一个/开始最后一个\的长度
string P_str_filename = //获取文件名
P_str_all.Substring(P_str_all.LastIndexOf("\\") + , //从最后一个/开始---到从最后一个/开始最后一个.的长度
P_str_all.LastIndexOf(".") -
(P_str_all.LastIndexOf("\\")+));
string P_str_fileexc = //获取文件扩展名
P_str_all.Substring(P_str_all.LastIndexOf(".") + ,//从最后一个.开始----到从最后一个.开始最后的长度
P_str_all.Length - P_str_all.LastIndexOf(".")-);
lb_filepath.Text = "文件路径: " + P_str_path;//显示文件路径
lb_filename.Text = "文件名称: " + P_str_filename;//显示文件名
lb_fileexc.Text = "文件扩展名: " + P_str_fileexc;//显示扩展名
}
} }
}

三:替换某一类字符串,上图

四:代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace ReplaceString
{
public partial class Frm_Main : Form
{
public Frm_Main()
{
InitializeComponent();
} private void btn_replace_Click(object sender, EventArgs e)
{
txt_str.Text = //使用字符串对象的Reaplce方法替换所有满足条件的字符串
txt_str.Text.Replace(txt_find.Text, txt_replace.Text);
}
}
}

从字符串总分离文件路径、命名、扩展名,Substring(),LastIndexOf()的使用;替换某一类字符串,Replace()的用法的更多相关文章

  1. ListView 根据 文件路径 或 扩展名 显示系统文件图标

    private void 获取文件button1_Click(object sender, EventArgs e)         {            folderBrowserDialog1 ...

  2. 使用任意的输入流(InputStream)实例,包括字符串形式的文件路径或者 file:// 的 URL 形式的文件路径来配置

    mybatis – MyBatis 3 | 入门 http://www.mybatis.org/mybatis-3/zh/getting-started.html 从 XML 中构建 SqlSessi ...

  3. 【技术宅3】截取文件和url扩展名的N种方法

    //截取文件扩展名的N种方法   //第1种 //strrchr() 函数查找字符在指定字符串中最后一次出现的位置,如果成功,则返回其后面的字符串 //返回带有点的扩展名 function get_e ...

  4. NO21 Llinux的文件种类与扩展名--文件权限--软硬链接--Linux删除文件原理

    Linux的文件种类与扩展名 一.文件种类:1.普通文件(regular file)第一个字符为[ - ]包括:①纯文本档(ASCII):这是Linux系统中最多的一种文件类型,称为纯文本档.是因为内 ...

  5. linux 常用命令: basename 去掉路径和扩展名

      basename: 去掉路径和扩展名 /bin/basename coreutils-8.4-9.el6.x86_64 basename命令用于去掉路径信息,返回纯粹的文件名,如果指定的文件的扩展 ...

  6. win7系统中如何使文件显示出扩展名

    win7系统中如何使文件显示出扩展名-------------------- 1.点击计算机-->>点击组织,然后选择"文件夹及搜索选项"-->> ---- ...

  7. win7系统中如何使文件显示出扩展名或显示文件后缀名

    win7系统中如何使文件显示出扩展名-------------------- 1.点击计算机-->>点击组织,然后选择“文件夹及搜索选项”-->> -------------- ...

  8. windows服务器设置文件属性设置去掉隐藏已知文件类型的扩展名(即文件后缀名可见)

    摘要: 1.文件后缀名不可见,系统运维过程容易发生同名不同后缀的文件操作混淆的情况 2.windows系统默认是文件后缀名不可见 3.所以需要更改一下配置. 4.操作步骤如下图: (1)点击组织-文件 ...

  9. System.IO.Path 文件名、路径、扩展名 处理

    string filePath =@"E:/Randy0528/中文目录/JustTest.rar"; 更改路径字符串的扩展名.System.IO.Path.ChangeExten ...

随机推荐

  1. LINQ高级编程 笔记

    相关资料:http://www.cnblogs.com/lifepoem/archive/2011/12/16/2288017.html 1.什么是LINQ 语言集成查询是一系列标准查询操作符的集合, ...

  2. 利用SQLiteOpenHelper创建数据库,进行增删改查操作

    Android中提供SQLiteOpenHelper类,在该类的构造器中,调用Context中的方法创建并打开一个指定名称的数据库对象.继承和扩展SQLiteOpenHelper类主要做的工作就是重写 ...

  3. NetAdvantage webdatagrid 控件的一些属性

    属性: 1 behaviors 行为下的属性集合 Row Selectors 主要用于设置行选择样式与形为的集合 Enable 属性表示是否启用 Row Selectors下的属性设置 RowNumB ...

  4. Nginx配置http强制跳转到https

    目的:访问http://sdk.open.test.com/时强制自动跳转到https://sdk.open.test.com/ 修改nginx站点配置文件sdk.open.test.com.conf ...

  5. xcode7 icon图标设置

  6. ccui.ScrollView 扩展

    大多数游戏都有背包这个东西. 道具列表通常用 ScrollView 来实现. 这个ScrollView内部有一个Layout, 滑动都是由移动这个Layout来实现. 道具摆放通常从上往下, 从左到右 ...

  7. 【POJ2887】【块状链表】Big String

    Description You are given a string and supposed to do some string manipulations. Input The first lin ...

  8. 利用sfntly的sfnttool.jar提取中文字体

    雨忆博客中提到了sfntly(具体介绍可以看:https://code.google.com/p/sfntly/),利用其中sfnttool.jar就可以提取只包含指定字符的字体,如果想在页面中通过@ ...

  9. MySql数据库1【概念】

    [mysql] mysql是目前最主流的跨平台.开放源代码的关系型数据库,由瑞曲的mysql ab公司开发,已经被SUN公司收购,标识是一只名为sakila的海豚,代表mysql的速度.能力.精确优秀 ...

  10. jQuery API中文文档

    jQuery API中文文档 http://www.css88.com/jqapi-1.9/category/events/event-handler-attachment/ jQuery UI AP ...