diff --git a/src/Logic/Utilities.cs b/src/Logic/Utilities.cs index d31f48fc0..5a4b4bf50 100644 --- a/src/Logic/Utilities.cs +++ b/src/Logic/Utilities.cs @@ -2736,24 +2736,23 @@ namespace Nikse.SubtitleEdit.Logic text = text.Replace(operatingSystemCommand, string.Empty); text = text.Replace('\t', ' '); - while (text.Contains(" ")) - text = text.Replace(" ", " "); - - text = text.Replace(" " + Environment.NewLine, Environment.NewLine); - text = text.Replace(Environment.NewLine + " ", Environment.NewLine); + text = text.FixExtraSpaces(); if (text.EndsWith(' ')) - text = text.TrimEnd(' '); + text = text.Substring(0, text.Length - 1); + + const string ellipses = "..."; + text = text.Replace(". . ..", ellipses); + text = text.Replace(". ...", ellipses); + text = text.Replace(". .. .", ellipses); + text = text.Replace(". . .", ellipses); + text = text.Replace(". ..", ellipses); + text = text.Replace(".. .", ellipses); + + // Fix recursive: ... + while (text.Contains("....")) + text = text.Replace("....", ellipses); - text = text.Replace(". . ..", "..."); - text = text.Replace(". ...", "..."); - text = text.Replace(". .. .", "..."); - text = text.Replace(". . .", "..."); - text = text.Replace(". ..", "..."); - text = text.Replace(".. .", "..."); - text = text.Replace("....", "..."); - text = text.Replace("....", "..."); - text = text.Replace("....", "..."); text = text.Replace(" ..." + Environment.NewLine, "..." + Environment.NewLine); text = text.Replace(Environment.NewLine + "... ", Environment.NewLine + "..."); text = text.Replace(Environment.NewLine + "... ", Environment.NewLine + "...");