using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string l = getFilename(@"c:\program files\Maths\all.dat");
Console.WriteLine(l);
confime(@"c:\program files\Maths\all.dat");
}//1、定义一个静态成员方法,该方法用于提取文件名。比如,给定一个字符串“c:\program files\Maths\all.dat”,使用该方法即可获取文件名all.dat
public static string getFilename(string file)
{
//提示:主体中使用string类的indexof方法和substring方法
string t = file.Substring(23);
return t;
}//自行设计程序验证上述方法正确性
public static void confime(string file1)
{
int f = file1.IndexOf("a", 23);
if (f == -1)
{
Console.Write("验证错误");
}
else
{
Console.Write("验证正确");
}
}
}
}

c#--怎样使用c#中的indexof和substring方法
最新推荐文章于 2024-08-10 17:55:20 发布