Hi there,
I tried this function that you have has an example, but I got an object null reference in foreach:
Here is the function:
private void ReplaceAllMatches(string toSearch, string toReplaceWith,RadDocument doc)
{
toSearch = Regex.Escape(toSearch);
doc.Selection.Clear();
DocumentTextSearch search = new DocumentTextSearch(doc);
List<TextRange> rangesTrackingDocumentChanges = new List<TextRange>();
foreach (var textRange in search.FindAll(toSearch))
{
TextRange newRange = new TextRange(new DocumentPosition(textRange.StartPosition, true), new DocumentPosition(textRange.EndPosition, true));
rangesTrackingDocumentChanges.Add(newRange);
}
foreach (var textRange in rangesTrackingDocumentChanges)
{
doc.Selection.AddSelectionStart(textRange.StartPosition);
doc.Selection.AddSelectionEnd(textRange.EndPosition);
doc.Insert(toReplaceWith,null);
textRange.StartPosition.Dispose();
textRange.EndPosition.Dispose();
}
}
Any idea why?
Note: My toSearch = "[ Tag_TipoReuniao ]", is because of that? But I did toSearch = Regex.Escape(toSearch);
If help you, I did:
try
{
IEnumerable<TextRange> lista = search.FindAll(toSearch);
}
catch(Exception erro)
{ MessageBox.Show("ERRO: " + erro.StackTrace); }
And the result are in attach.
Help please...
Thanks
I tried this function that you have has an example, but I got an object null reference in foreach:
Here is the function:
private void ReplaceAllMatches(string toSearch, string toReplaceWith,RadDocument doc)
{
toSearch = Regex.Escape(toSearch);
doc.Selection.Clear();
DocumentTextSearch search = new DocumentTextSearch(doc);
List<TextRange> rangesTrackingDocumentChanges = new List<TextRange>();
foreach (var textRange in search.FindAll(toSearch))
{
TextRange newRange = new TextRange(new DocumentPosition(textRange.StartPosition, true), new DocumentPosition(textRange.EndPosition, true));
rangesTrackingDocumentChanges.Add(newRange);
}
foreach (var textRange in rangesTrackingDocumentChanges)
{
doc.Selection.AddSelectionStart(textRange.StartPosition);
doc.Selection.AddSelectionEnd(textRange.EndPosition);
doc.Insert(toReplaceWith,null);
textRange.StartPosition.Dispose();
textRange.EndPosition.Dispose();
}
}
Any idea why?
Note: My toSearch = "[ Tag_TipoReuniao ]", is because of that? But I did toSearch = Regex.Escape(toSearch);
If help you, I did:
try
{
IEnumerable<TextRange> lista = search.FindAll(toSearch);
}
catch(Exception erro)
{ MessageBox.Show("ERRO: " + erro.StackTrace); }
And the result are in attach.
Help please...
Thanks