using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace CoreCms.Net.Utility.Extensions
{
///
/// 字符串扩展
///
public static class StringExtensions
{
///
/// str 转int
///
///
///
///
public static int ToInt32OrDefault(this string value, int defaultValue = 0)
{
if (int.TryParse(value, out int result))
{
return result;
}
return defaultValue;
}
///
/// 将yyyy-MM-dd'T'HH:mm:ss~yyyy-MM-dd'T'HH:mm:ss 格式未StartDate 和enddata
///
///
///
public static (DateTime? StartDate, DateTime? EndDate) ParseDateTimeRange(this string input)
{
// 定义日期时间格式
string format = "yyyy-MM-dd'T'HH:mm:ss";
// 拆分字符串
string[] parts = input.Split('~');
if (parts.Length == 2)
{
// 解析开始时间
DateTime startDate;
bool isStartDateValid = DateTime.TryParseExact(parts[0], format, null, System.Globalization.DateTimeStyles.None, out startDate);
// 解析结束时间
DateTime endDate;
bool isEndDateValid = DateTime.TryParseExact(parts[1], format, null, System.Globalization.DateTimeStyles.None, out endDate);
if (isStartDateValid && isEndDateValid)
{
if(startDate
/// 校验是否是手机号码
///
///
///
public static bool IsPhoneNumberValid(this string phoneNumber)
{
// 定义正则表达式模式
string pattern = @"^1[3-9]\d{9}$";
// 使用 Regex.IsMatch 方法进行匹配
return Regex.IsMatch(phoneNumber, pattern);
}
}
}