您的位置:首页 > 其它

查找字符串中的子串

2016-03-18 16:41 246 查看
假设有一个字符串“D:\C#程序设计\实验3\MyFile.TXT “取出路径中的文件名“MyFile.TXT”

示例代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
String strFileName = @"D:\C#程序设计\实验3\MyFile.TXT";
Console.WriteLine(getFilename(strFileName));
Console.ReadKey();
}
public static string getFilename(String strFileName)
{

return strFileName.Substring(strFileName.LastIndexOf("M"),strFileName.LastIndexOf("T") - strFileName.LastIndexOf("M")+1);
}
}
}


本示例代码采用String类中取子串Substring(int startIndex,int length)方法
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: