diff --git a/PROMS/Volian.Controls.Library/DisplayText.cs b/PROMS/Volian.Controls.Library/DisplayText.cs index 1ffb2427..a41d3802 100644 --- a/PROMS/Volian.Controls.Library/DisplayText.cs +++ b/PROMS/Volian.Controls.Library/DisplayText.cs @@ -1718,12 +1718,31 @@ namespace Volian.Controls.Library { if (foundMatch.MyWord != null) { - text = text.Substring(0, offset + foundMatch.MyMatch.Index) + foundMatch.MyWord.ReplaceWith + text.Substring(offset + foundMatch.MyMatch.Index + foundMatch.MyMatch.Length); - offset += foundMatch.MyWord.ReplaceWith.Length - foundMatch.MyMatch.Length; + if (VerifyNoHardSpace(text, foundMatch, offset)) + { + text = text.Substring(0, offset + foundMatch.MyMatch.Index) + foundMatch.MyWord.ReplaceWith + text.Substring(offset + foundMatch.MyMatch.Index + foundMatch.MyMatch.Length); + offset += foundMatch.MyWord.ReplaceWith.Length - foundMatch.MyMatch.Length; + } } } return text; } + + private bool VerifyNoHardSpace(string text, FoundMatch foundMatch, int offset) + { + string begin = text.Substring(0, offset + foundMatch.MyMatch.Index); + string end = text.Substring(offset + foundMatch.MyMatch.Index + foundMatch.MyMatch.Length); + if (text.StartsWith(@"{\rtf")) + { + // make sure that it is not preceded by \u160? \'a0 or \~ + if(Regex.IsMatch(begin,@"(\\(u160\?|'a0|~)(\\f[0-9]* ?)*(\\fs[0-9]* ?)*)$")) + return false; + // make sure that it is not followed by \u160? \'a0 or \~ + if(Regex.IsMatch(end,@"^((\\f[0-9]* ?)*(\\fs[0-9]* ?)*\\(u160\?|'a0|~))")) + return false; + } + return true; + } } public class FoundMatch {