@@ -959,30 +959,13 @@ public void ReplaceText(string search, string replacement, bool useRegex = false
959959 try
960960 {
961961 var updatedElements = new List < IElement > ( ) ;
962-
963- // Compile regex pattern once
964962 var regex = useRegex
965963 ? new System . Text . RegularExpressions . Regex ( search )
966964 : new System . Text . RegularExpressions . Regex ( System . Text . RegularExpressions . Regex . Escape ( search ) ) ;
967-
968- // Local helper for paragraph processing
969- /**
970- void ProcessParagraph(Paragraph para)
971- {
972- if (regex.IsMatch(para.Text))
973- {
974- Console.WriteLine("Match Found");
975- para.ReplaceText(search, replacement, useRegex);
976- //updatedElements.Add(para);
977- }
978- }
979- **/
980-
981965 foreach ( var element in _lstStructure )
982966 {
983967 if ( element is Paragraph para )
984968 {
985- //ProcessParagraph(para);
986969 if ( regex . IsMatch ( para . Text ) )
987970 {
988971 para . ReplaceText ( search , replacement , useRegex ) ;
@@ -1002,13 +985,7 @@ void ProcessParagraph(Paragraph para)
1002985 {
1003986 cellPara . ReplaceText ( search , replacement , useRegex ) ;
1004987 isMatched = true ;
1005- //updatedElements.Add(para);
1006988 }
1007-
1008- //ProcessParagraph(cellPara);
1009- //count++;
1010- //cell.Paragraphs[count] = cellPara;
1011- //updatedElements.Add(cellPara);
1012989 }
1013990 }
1014991 }
@@ -1018,8 +995,6 @@ void ProcessParagraph(Paragraph para)
1018995 }
1019996 }
1020997 }
1021-
1022- // Apply updates in a separate loop
1023998 foreach ( var element in updatedElements )
1024999 {
10251000 this . Update ( element . ElementId , element ) ;
@@ -1032,57 +1007,6 @@ void ProcessParagraph(Paragraph para)
10321007 }
10331008 }
10341009
1035- /**
1036- public void ReplaceText(string search, string replacement, bool useRegex = false)
1037- {
1038- var updatedElements = new List<IElement>();
1039-
1040- // Compile the regex pattern once
1041- var regex = useRegex
1042- ? new System.Text.RegularExpressions.Regex(search)
1043- : new System.Text.RegularExpressions.Regex(System.Text.RegularExpressions.Regex.Escape(search));
1044-
1045- foreach (var element in _lstStructure)
1046- {
1047- if (element is Paragraph para)
1048- {
1049- var matches = regex.Matches(para.Text);
1050- if (matches.Count > 0)
1051- {
1052- Console.WriteLine("Match Found");
1053- para.ReplaceText(search, replacement, useRegex);
1054- updatedElements.Add(para);
1055- }
1056- }
1057- if (element is Table table)
1058- {
1059- foreach (var row in table.Rows)
1060- {
1061- foreach (var cell in row.Cells)
1062- {
1063- foreach (var cellPara in cell.Paragraphs)
1064- {
1065- var matches = regex.Matches(cellPara.Text);
1066- if (matches.Count > 0)
1067- {
1068- cellPara.ReplaceText(search, replacement, useRegex);
1069- updatedElements.Add(cellPara);
1070- }
1071- }
1072- }
1073- }
1074- }
1075- }
1076-
1077- // Apply updates in a separate loop
1078- foreach (var element in updatedElements)
1079- {
1080- this.Update(element.ElementId, element);
1081- }
1082-
1083- }
1084- **/
1085-
10861010 /// <summary>
10871011 /// Dispose off all managed and unmanaged resources.
10881012 /// </summary>
0 commit comments