这应包括您的要求的所有3。请原谅格式化;我必须重新选择
的前几行才能正确显示。
string pattern = @"(?<!^| )((?<!\s) (?!\s))(?!\1)";
string[] inputs = { " AA A C D A Some Text here", // original
" AA A C D A Some Text here" // space before/after
};
foreach (string input in inputs)
{
string result = Regex.Replace(input, pattern, "#");
Console.WriteLine("Original: {0}\nResult: {1}", input, result);
}
输出:
Original: AA A C D A Some Text here
Result: AA#A C#D A#Some Text here
Original: AA A C D A Some Text here
Result: AA#A C#D A Some Text here
非常感谢。下次我会简单地给你发送我的消息来修复:) 优秀的例子!!! – ManniAT 2009-09-15 11:04:12