using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

public static class StringExtensions
{
    /// <summary>
    /// 下划线转为驼峰
    /// </summary>
    /// <param name="str"></param>
    /// <param name="initialsUppder"></param>
    /// <returns></returns>
    public static string ToCamelCase(this string str, char split = '_', bool initialsUppder = true)
    {
        var _ = string.Join("",
            str.Split(split).Select(p => p.Length > 1 ?
                p.First().ToString().ToUpper() + p[1..] : p.ToUpper()
            )
        );

        if (!initialsUppder && _.Length > 1)
        {
            _ = _.First().ToString().ToUpper() + _[1..];
        }

        return _;
    }

    /// <summary>
    /// 驼峰转为下划线
    /// </summary>
    /// <param name="str"></param>
    /// <returns></returns>
    public static string ToUnderScoreCase(this string str)
    {
        var _ = new Regex(@"[A-Z]").Replace(str, "_$0");

        if (_.Length > str.Length)
        {
            _ = _[1..];
        }

        return _.ToLower();
    }
}
