using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
public static class StringExtensions
{
///
/// 下划线转为驼峰
///
///
///
///
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 _;
}
///
/// 驼峰转为下划线
///
///
///
public static string ToUnderScoreCase(this string str)
{
var _ = new Regex(@"[A-Z]").Replace(str, "_$0");
if (_.Length > str.Length)
{
_ = _[1..];
}
return _.ToLower();
}
public static DateTime GetNow(this DateTime timestamp)
{
return DateTimeOffset.Now.ToOffset(TimeSpan.FromHours(8)).DateTime;
}
}