尝试:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string[] inputs =
{
"!WTE|VESA * U:miam @contoso.com | VE * U:hasan @microsoft.com | VES",
"!Z CRE Forms | VESA * Dept IT Users| VS",
"!U: miam @contoso.com | VESA * U:hasan @microsoft.com | VESA"
};
foreach(string input in inputs)
{
string[] splitArray = input.Substring(1).Replace("|", " ").Split(new char[] { * });
foreach(string line in splitArray)
{
string output = line.Trim();
if(output.Contains(":"))
{
output = output.Substring(output.IndexOf(":") + 1).Trim();
}
output = Regex.Replace(output, @"s+", " ");
output = Regex.Replace(output, @"s@", "@");
Console.WriteLine(output);
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
后果
WTE VESA
miam@contoso.com VE
hasan@microsoft.com VES
Z CRE Forms VESA
Dept IT Users VS
miam@contoso.com VESA
hasan@microsoft.com VESA