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方法
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.