This is a migrated thread and some comments may be shown as answers.

Error on ReplaceAllMatches in telerik's example

1 Answer 95 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Manuel
Top achievements
Rank 1
Manuel asked on 28 Dec 2011, 01:30 PM
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

1 Answer, 1 is accepted

Sort by
0
Manuel
Top achievements
Rank 1
answered on 29 Dec 2011, 03:23 PM
Hi there,

I already fix it. I solved the problem replace the string that I passed from "[ Tag_TipoReuniao ]" to "Tag_TipoReuniao".
Tags
RichTextBox
Asked by
Manuel
Top achievements
Rank 1
Answers by
Manuel
Top achievements
Rank 1
Share this question
or