From 85771b0dda8b028833bd4a055e4697dba9380fa2 Mon Sep 17 00:00:00 2001 From: Rich Date: Sat, 24 Jan 2015 23:13:55 +0000 Subject: [PATCH] Fix DoROReplaceWords So that parts of words are not affected --- PROMS/Volian.Controls.Library/DisplayText.cs | 21 +++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/PROMS/Volian.Controls.Library/DisplayText.cs b/PROMS/Volian.Controls.Library/DisplayText.cs index d4552b79..cc571348 100644 --- a/PROMS/Volian.Controls.Library/DisplayText.cs +++ b/PROMS/Volian.Controls.Library/DisplayText.cs @@ -121,7 +121,7 @@ namespace Volian.Controls.Library _MyItemInfo = itemInfo; OriginalText = InfoText; if (OriginalText.Contains("Prerequisite") && epMode == E_EditPrintMode.Print) - OriginalText = Regex.Replace(OriginalText, @"\\{Prerequisite Step: .*?\\}", ""); + OriginalText = Regex.Replace(OriginalText, @"\\{Prerequisite Step: .*?\\}", ""); TextFont = itemInfo.GetItemFont();//GetItemFont(); // if in print mode, and this is the HLS of a smart template (checklist formats) see if the hls // splits across 2 lines. @@ -538,15 +538,30 @@ namespace Volian.Controls.Library } return text; } - private string DoROReplaceWords(ReplaceStrList replaceStrList, string newvalue, bool isHigh) + private string DoROReplaceWords(ReplaceStrList replaceStrList, string oldvalue, bool isHigh) { + int profileDepth = ProfileTimer.Push(">>>> DoROReplaceWords"); + string newvalue = oldvalue; foreach (ReplaceStr rs in replaceStrList) { if (((rs.Flag & E_ReplaceFlags.Setpoint) > 0) || (isHigh && (rs.Flag & E_ReplaceFlags.HLSSetpnt) > 0)) { - newvalue = newvalue.Replace(rs.ReplaceWord, rs.ReplaceWith); + try + { + // Use regular expression to assure that the ReplaceWord is not part of another word + // For VEPROMS_CAL E-0 Step 23 (Reset SI) the word "after" was being changed to "aFTer" + newvalue = Regex.Replace(newvalue, @"(?<=\W|^)" + rs.ReplaceWord + @"(?=\W|$)", rs.ReplaceWith); + //newvalue = newvalue.Replace(rs.ReplaceWord, rs.ReplaceWith); + } + catch (Exception ex) + { + _MyLog.Warn("Problem with regular expression", ex); + } } } + //if (oldvalue != newvalue) + // Console.WriteLine("\"{0}\"\r\n\"{1}\"",oldvalue,newvalue); + ProfileTimer.Pop(profileDepth); return newvalue; } // Replace spaces with hardspaces, but DO NOT replace the end of an Rtf Command with a hardspace