字符的处理及列出文件夹中的所有文件名

using System;
using System.IO;
using System.Text;
class test

    static void Main()
    {
        //以下为替换单个字符,将输入的字符进行替换
        //Console.Write("enter a same words:");
        //String str = Console.ReadLine();
        //Char[] arr = str.ToCharArray(0,str.Length);//转换成字符数组
        //for (int i = 0; i < str.Length; i++)
        //{
        //    if (arr[i] == 'a')
        //    {
        //        arr[i] = 'w';
        //    }
        //    Console.Write(arr[i]);
        //}


        以下为替换一个字符串
        //Console.Write("enter words :");
        //String str = Console.ReadLine();
        //Console.WriteLine(str);
        //String newstr = str.Replace("wen", "xiong");//将str字符串中的wen转换成xiong
        //Console.WriteLine(newstr);
        //Console.WriteLine(str);


        //以下方法判断一个路径下的文件存不存在
        //if (!File.Exists(@"F:\C#study\wenfuchun.cs")) //File.Exists判断当前path路径是否存在
        //{
        //    File.Create(@"F:\C#study\wenfuchun.cs");
        //}
        //else


        //{
        //    Console.WriteLine("输入的路径已经存在");
        //}


        //以下方法取出一个文件路径中的文件名,不含后缀
        //Console.WriteLine("the next is post the path name:");
        //String pathname = Path.GetFileNameWithoutExtension(@"F:\C#study\wenfuchun.cs");
        //Console.WriteLine(pathname);


        //以下方法在控制台中列出(F:\\C#study\\)目录下的所有文件名及其后缀
        DirectoryInfo path = new DirectoryInfo(@"F:\C#study\");//(@"F:\C#study\")改成(F:\\C#study\\)是一样的
        FileInfo[] arr = path.GetFiles();
        //使用foreach输出
        //foreach (FileInfo ph in arr)
        //{
        //    Console.WriteLine(ph.Name);
        //}
        //使用for循环输出
        for (int i = 0; i < arr.Length;i++ )
        {
            Console.WriteLine("the id number {0}:{1}",i,arr[i].Name);
        }


    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值