修改
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Text;
|
||||
using ConsoleApp2.Options;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace ConsoleApp2.Helpers;
|
||||
@@ -11,9 +12,9 @@ public static partial class DumpDataHelper
|
||||
private static partial Regex MatchBrackets();
|
||||
|
||||
|
||||
public static async Task<string[]> GetCsvHeadersFromSqlFileAsync(string filePath)
|
||||
public static async Task<string[]> GetCsvHeadersFromSqlFileAsync(string txt)
|
||||
{
|
||||
var txt = await File.ReadAllTextAsync(filePath);
|
||||
//var txt = await File.ReadAllTextAsync(filePath);
|
||||
var match = MatchBrackets().Match(txt);
|
||||
|
||||
return ParseHeader(match.ValueSpan);
|
||||
@@ -59,10 +60,10 @@ public static partial class DumpDataHelper
|
||||
return filePath[(firstDotIdx+1)..secondDotIdx].ToString();
|
||||
}
|
||||
|
||||
public static async Task<string[]> GetCsvFileNamesFromSqlFileAsync(string filePath)
|
||||
public static async Task<string[]> GetCsvFileNamesFromSqlFileAsync(string txt,Regex regex)
|
||||
{
|
||||
var txt = await File.ReadAllTextAsync(filePath);
|
||||
var matches = MatchDatFile().Matches(txt);
|
||||
//var txt = await File.ReadAllTextAsync(filePath);
|
||||
var matches = regex.Matches(txt);
|
||||
return matches.Select(match => match.ValueSpan[1..^1].ToString()).ToArray();
|
||||
}
|
||||
|
||||
|
31
ConsoleApp2/Helpers/ValidateConsole.cs
Normal file
31
ConsoleApp2/Helpers/ValidateConsole.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConsoleApp2.Helpers
|
||||
{
|
||||
public static class ValidateConsole
|
||||
{
|
||||
public static void ValidateInput<T>(Func<string,bool> converter,string message)
|
||||
{
|
||||
Console.Write(message);
|
||||
string ? input = Console.ReadLine();
|
||||
while (true)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(input))
|
||||
{
|
||||
var result = converter(input);
|
||||
if (result == false)
|
||||
{
|
||||
Console.WriteLine($"输入的内容不合法,请重新输入!");
|
||||
input = Console.ReadLine();
|
||||
}
|
||||
else break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user