StringHelper

作者:追风剑情 发布于:2025-6-15 14:31 分类:Unity3d

using System;
using System.Text.RegularExpressions;
/// <summary>
/// 字符串处理辅助类
/// </summary>
public sealed class StringHelper
{
    // 去除代码注释
    public static string StripCodeComment(string code)
    {
        //删除单行注释
        //(.*?): 非贪婪匹配任意字符(除了换行符)
        //$: 匹配行尾
        string patternSingleLine = @"//.*?$";
        code = Regex.Replace(code, patternSingleLine, string.Empty, RegexOptions.Multiline);

        //删除多行注释
        string patternMultiLine = @"/\*(.|\n)*?\*/";
        code = Regex.Replace(code, patternMultiLine, string.Empty, RegexOptions.Multiline);

        return code;
    }
}

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号