using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; namespace KssSmaPlaLib.Commons { public class StringUxer { public static bool WildcardMatch(string input, string pattern) { // "*" を ".*" に変換し、正規表現にする string regexPattern = "^" + Regex.Escape(pattern).Replace("\\*", ".*") + "$"; return Regex.IsMatch(input, regexPattern, RegexOptions.IgnoreCase); } // public static bool TryParseIniSignature(string iniValue, out string functionName, out List args) // { // functionName = null; // args = null; // var pattern = @"^([a-zA-Z_][a-zA-Z0-9_]*)\((.*?)\)$"; // var match = Regex.Match(iniValue.Trim(), pattern); // if (!match.Success) // return false; // functionName = match.Groups[1].Value; // var argsString = match.Groups[2].Value; // args = string.IsNullOrEmpty(argsString) // ? new List() // : argsString.Split(',').Select(arg => arg.Trim()).ToList(); // return true; // } public static bool TryExtractYearFromString(string str, out int year) { // var match = Regex.Match(str, @"\b(20\d{2})\b"); // 条件厳しめ var match = Regex.Match(str, @"(20\d{2})"); // 条件緩め year = match.Success ? int.Parse(match.Groups[1].Value) : -1; return year != -1; } /// /// CSVから文字列取得(インデックス指定:範囲外の時既定値) /// /// CSV文字列(カンマ区切り) /// インデックス /// 範囲外の時の既定値 /// 取得した文字列 public static string GetStringByIndexFormCsv(string csv, int index, string noString = "(No name...)") { string[] strSplit = csv.Split(','); if (index < 0 || index > strSplit.Length - 1) return noString; return strSplit[index]; } } }