110,539
社区成员
发帖
与我相关
我的任务
分享
//.NET FREAMEWORK3.5+版本 编译通过
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string str = "adt 12 ce 63 02251 2634";
str = Regex.Replace(Regex.Replace(str, @"(?i)[^a-f\d\s]+", ""), "\\w{3,}",
m=> string.Join(" ", Regex.Split(m.Value, @"(?<=\G\w{2})(?!$)").Select(x => x.PadLeft(2, '0')).ToArray())).ToUpper();
Console.WriteLine(str); //AD 12 CE 63 02 25 01 26 34
Console.ReadKey();
}
}
}
void Main()
{
string str="adt 12 ce 63 02251 2634";
str=Regex.Replace(Regex.Replace(str,@"(?i)[^a-f\d\s]+",""),"\\w{3,}",
m=>string.Join(" ",Regex.Split(m.Value,@"(?<=\G\w{2})(?!$)").Select(x=>x.PadLeft(2,'0')).ToArray())).ToUpper();
Console.WriteLine(str); //AD 12 CE 63 02 25 01 26 34
}