• C# 普通的辅助类


    在数字前面补0

            /// <summary>
            /// 在数字前面添加0
            /// </summary>
            /// <param name="num">数字</param>
            /// <param name="ws">添加0后的位数</param>
            /// <returns></returns>
            public string numPadLeftzero(string num ,int ws)
            {
                return num.ToString().PadLeft(ws, '0'); 
            }
    在数字前面补0
            /// <summary>
            /// 去除数字前面的0 
            /// </summary>
            /// <param name="num">数字</param>
            /// <returns></returns>
            public string numRemovezero(string num)
            {
                string r = @"[1-9]d+";
                string n = System.Text.RegularExpressions.Regex.Match(num, r).ToString();    //提取信息 
                return n;
            }
    去除数据前面的0
    /// <summary>
            /// 将传入的数据写入TXT文件中
            /// <param name="data">要储存的数据</param>
            public static void writeLogData(string data)
            {
                string path = Application.StartupPath + "\Log\";
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
    
                path = path + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
                if (!File.Exists(path))
                {
                    FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);
                    StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
                    long fl = fs.Length;
                    fs.Seek(fl, SeekOrigin.End);
                    sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff") + "==>" + data);//开始写入值
                    sw.Close();
                    fs.Close();
                }
                else
                {
                    FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Write);
                    StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
                    long fl = fs.Length;
                    fs.Seek(fl, SeekOrigin.Begin);
                    sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff") + "==>" + data);//开始写入值
                    sw.Close();
                    fs.Close();
                }
    
            }
    将数据保存到xml中
  • 相关阅读:
    在线图片压缩
    wiki-editor语法
    Android 4.0.4模拟器安装完全教程(图文)
    Javascript中的void
    守护进程
    jQuery编程的最佳实践
    JavaScript内存优化
    vim编程技巧
    MySQL表的四种分区类型
    SQL中的where条件,在数据库中提取与应用浅析
  • 原文地址:https://www.cnblogs.com/cl1006/p/10854920.html
Copyright © 2020-2023  润新知