私は正しく理解したことを願っています-うまくいけば、これはあなたが始めるのに役立つでしょう。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
string basePath = "c:\\temp";
List<string> filenames = new List<string>();
filenames.Add("monster3456 test");
filenames.Add("ketchup1234 make");
filenames.Add("oranges5555 build");
foreach (string filename in filenames)
{
Match match = Regex.Match(filename, @"([a-z]+)([0-9]+)[^\S]{1,}(\w+)", RegexOptions.IgnoreCase);
if (match.Success)
{
string alpha = match.Groups[1].Value.Substring(0, 1);
string alphaString = match.Groups[1].Value;
string uniqueSet = match.Groups[2].Value;
string instance = match.Groups[3].Value;
string finalInstance = String.Empty;
string path = String.Empty;
switch (instance.ToLower())
{
case "test":
finalInstance = "Tester";
break;
case "make":
finalInstance = "Maker";
break;
case "build":
finalInstance = "Builder";
break;
default:
break;
}
if (!String.IsNullOrEmpty(finalInstance))
{
path = basePath + "\\" + alpha + "\\" + alphaString + uniqueSet + "\\" + finalInstance;
Console.WriteLine(path);
/* Console.WriteLine("alpha: " + alpha);
Console.WriteLine("alphaString: " + alphaString);
Console.WriteLine("uniqueSet: " + uniqueSet);
Console.WriteLine("finalInstance: " + finalInstance); */
}
}
}
Console.Read();
}
}
}
出力
c:\temp\m\monster3456\Tester
c:\temp\k\ketchup1234\Maker
c:\temp\o\oranges5555\Builder