You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
130 lines
3.7 KiB
130 lines
3.7 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace Apewer.Run
|
|
{
|
|
|
|
class Config
|
|
{
|
|
|
|
public Config()
|
|
{
|
|
Test(typeof(Config).FullName, "");
|
|
Test(typeof(Config).FullName, ",");
|
|
Test(typeof(Config).FullName, ".");
|
|
}
|
|
|
|
void Test(string input, string separator)
|
|
{
|
|
var split = Split_Agent(input, separator);
|
|
Console.Write(input + " | " + separator + " | ");
|
|
Console.WriteLine(string.Join(" - ", split));
|
|
}
|
|
|
|
public static string[] Split_Agent(string @this, params string[] saparators)
|
|
{
|
|
var text = @this;
|
|
if (string.IsNullOrEmpty(text)) return new string[0];
|
|
if (saparators == null || saparators.LongLength < 1L) return new string[1] { text };
|
|
|
|
var ss = new List<string>();
|
|
foreach (var s in saparators)
|
|
{
|
|
if (string.IsNullOrEmpty(s)) continue;
|
|
if (ss.Contains(s)) continue;
|
|
ss.Add(s);
|
|
}
|
|
|
|
var parts = new List<string>();
|
|
var length = 0;
|
|
var sample = text;
|
|
var saparator = null as string;
|
|
while (true)
|
|
{
|
|
if (sample.Length < 0)
|
|
{
|
|
parts.Add(sample);
|
|
break;
|
|
}
|
|
|
|
length = -1;
|
|
saparator = null;
|
|
foreach (var s in ss)
|
|
{
|
|
var i = sample.IndexOf(s);
|
|
if (i > -1)
|
|
{
|
|
length = i;
|
|
saparator = s;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (saparator == null)
|
|
{
|
|
parts.Add(sample);
|
|
break;
|
|
}
|
|
|
|
var part = sample.Substring(0, length);
|
|
parts.Add(part);
|
|
|
|
sample = sample.Substring(length + saparator.Length);
|
|
}
|
|
|
|
return parts.ToArray();
|
|
}
|
|
|
|
public static string[] Split(string argExpression, string argSeparator)
|
|
{
|
|
var expression = argExpression;
|
|
var separator = argSeparator;
|
|
if (string.IsNullOrEmpty(expression)) return new string[] { "" };
|
|
if (string.IsNullOrEmpty(separator)) return new string[] { expression };
|
|
if (separator.Length > expression.Length) return new string[] { expression };
|
|
|
|
var list = new List<string>();
|
|
var position = 0;
|
|
var total = expression.Length;
|
|
var length = separator.Length;
|
|
var cell = new StringBuilder();
|
|
while (position < total)
|
|
{
|
|
var read = (position + length < total) ? expression.Substring(position, length) : expression.Substring(position);
|
|
if (read == separator)
|
|
{
|
|
if (cell.Length > 0)
|
|
{
|
|
list.Add(cell.ToString());
|
|
#if NET20
|
|
cell = new StringBuilder();
|
|
#else
|
|
cell.Clear();
|
|
#endif
|
|
}
|
|
else
|
|
{
|
|
list.Add("");
|
|
}
|
|
position += length;
|
|
}
|
|
else
|
|
{
|
|
cell.Append(expression[position]);
|
|
position += 1;
|
|
}
|
|
|
|
if (position >= total)
|
|
{
|
|
list.Add(cell.ToString());
|
|
}
|
|
}
|
|
|
|
var array = list.ToArray();
|
|
return array;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|