日期:2014-05-17 浏览次数:21122 次
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
class Program
{
static Dictionary<string, string> MyScanf(string format, params string[] values)
{
var result = Regex.Match(Console.ReadLine(), format).Groups;
return values.Select((x, i) => new { key = x, value = result[i + 1].Value })
.ToDictionary(x => x.key, x => x.value);
}
static void Main(string[] args)
{
var input = MyScanf(@"(\d+) (\d+)", "a", "b");
Console.WriteLine("your input is a = {0}, b = {1}.", input["a"], input["b"]);
}
}
}