這應包括您的要求的所有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