浙江省高等学校教师教育理论培训

微信搜索“毛凌志岗前心得”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
  12653 随笔 :: 2 文章 :: 617 评论 :: 609万 阅读

我有一段代码,如下,以前写的,不命名不规范,都以小写的get打头,我想把它改成以Get打头,于是想到了正则

 

复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Utils
{
    
class DateTimeHelper
    {
        public static string getYear()
        {
            
return DateTime.Now.Year.ToString();
        }
        public string getMonth()
        {
            
return Microsoft.VisualBasic.Strings.Right("00" + DateTime.Now.Month.ToString(), 2);
        }
        public string getDay()
        {
            
return Microsoft.VisualBasic.Strings.Right("00" + DateTime.Now.Day.ToString(), 2);
        }
        public string getYYYYMMDD()
        {
            
return this.getYear() + this.getMonth() + this.getDay();
        }
        public string getHour()
        {
            
return vb.Right("00" + DateTime.Now.Hour.ToString(), 2);
        }
        public string getMinute()
        {
            
return vb.Right("00" + DateTime.Now.Minute.ToString(), 2);
        }
        public string getSecond()
        {
            
return vb.Right("00" + DateTime.Now.Second.ToString(), 2);
        }
        public string getMillsecond()
        {
            
return DateTime.Now.Millisecond.ToString();
        }
        public string getHHMMSS()
        {
            
return this.getHour() + this.getMinute() + this.getSecond();
        }
    }
}
复制代码

我在RegexBuddy下使用

 这里修改后的,对你或许还有点用

 

复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using vb 
= Microsoft.VisualBasic.Strings;
namespace Utils
{
    
class DateTimeHelper
    {
        public static string GetYear()
        {
            
return DateTime.Now.Year.ToString();
        }
        public static string GetMonth()
        {
            
return Microsoft.VisualBasic.Strings.Right("00" + DateTime.Now.Month.ToString(), 2);
        }
        public static string GetDay()
        {
            
return Microsoft.VisualBasic.Strings.Right("00" + DateTime.Now.Day.ToString(), 2);
        }
        public static string GetYYYYMMDD()
        {
            
return GetYear() + GetMonth() + GetDay();
        }
        public static string GetHour()
        {
            
return vb.Right("00" + DateTime.Now.Hour.ToString(), 2);
        }
        public static string GetMinute()
        {
            
return vb.Right("00" + DateTime.Now.Minute.ToString(), 2);
        }
        public static string GetSecond()
        {
            
return vb.Right("00" + DateTime.Now.Second.ToString(), 2);
        }
        public static string GetMillsecond()
        {
            
return DateTime.Now.Millisecond.ToString();
        }
        public static string GetHHMMSS()
        {
            
return GetHour() + GetMinute() + GetSecond();
        }
    }
}
复制代码

 烦请高手解答一下我的疑惑,在vistual studio 或是editplus中怎么实现这个正则的替换啊

 

posted on   lexus  阅读(2102)  评论(6编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示