zoukankan      html  css  js  c++  java
  • 将输入字符串转化为合法的文件名称

    将输入字符串转化为合法的文件名称

    using
     System;
    using System.Text;

    namespace ConvertFilenameToValid
    {
        //z 2012-3-5 13:17:35 PM IS2120@CSDN
        class Program
        {
            static void PrintUsage ()
            {
                System.Console.WriteLine ("Usage : ");
                System.Console.WriteLine (System.Reflection.Assembly.GetEntryAssembly ().GetName ().Name + " filename");
            }

            static void OutputValidFilename (StringBuilder fileName)
            {
                foreach (char c in System.IO.Path.GetInvalidFileNameChars ())
                {
                    fileName = fileName.Replace (c, '_');
                }

                System.Console.WriteLine (fileName);
            }

            //z 2012-3-5 13:17:35 PM IS2120N
            static void OutputValidFilename (string _fileName)
            {
                StringBuilder fileName = new StringBuilder (_fileName);

                OutputValidFilename (fileName);
            }

            static void Main (string[] args)
            {
                if (args.Length != 1)
                {
                    PrintUsage ();

                    return;
                }

                OutputValidFilename (args[0]);

                return;
            }
        }
    }

    //z 2012-3-5 13:17:35 PM IS2120@CSDN
  • 相关阅读:
    Manjaro mirror in china
    gnome3.X添加开机启动项
    ssh无密钥登陆的简单配置
    ESXi虚拟磁盘共享
    记录一次fat32格式U盘不识别问题
    更换内核后重编virtualbox内核模块
    宏定义字符串连接和符号粘贴
    kernel source reading notepad
    linux kernel tainted
    设计模式-观察者模式(Observer Pattern)
  • 原文地址:https://www.cnblogs.com/IS2120/p/6745933.html
Copyright © 2011-2022 走看看