Replacing a Regex Match Collection in C# -


I should get a text that starts with [and ends] and replaced with that value What does the function do? So, here's an example of what I'm doing here:

  public string process template (string input) {return reggax. Replay (Input, @ "\ [(* *.] \]", New match Evolution (match match) {return process blocks (match result ("$ 1"))})); } Public string process block (string value) {return Block.FromString (value). Process (); }  

Now, my problem occurs when I have to edit the block so I can search for blocks, edit them, and convert then to text Thought of

Therefore, I created a list of blocks and the ProcessTemplate method has two methods: FindBlocks and ReplaceBlocks :

  Public Zero FindBlocks (string input) {input = input; Fresh (match match in reggax. Matts (input, @ "\ [(. *.) \]")) Block Add (block frame string (match. Result ("$ 1")); } Public string ReplaceBlocks () {string input = input; (Block block block) input = input Change ("[" + block.OrginalText + "]", block.Process); Return input; } Public IList & lt; Block & gt; Blocks {receive; Set; } Public string input {get; Set; }  

This is working, but the problem is that it is very slow. I measured from System.Diagnostics.Stopwatch each part, and I found that the ReplaceBlocks method in String.Replace is very slow.

How can I improve it?

Thank you.

Replace string in ReplaceBlock with StringBuilder and provide performance enhancements each time you string Riley. It will have to delete the string and reload the string. The string builder does not need to do this.

Replace the contents of ReplaceBlock with the following.

  // This system will require a reference. Text stringbuilder input = new stringbiller (input); Fork (block block block) {input = input.Replace ("[" + block.OrginalText + "]", block.Process); } Return Input Toasting ();  

I have also found the place of foreach loops for loop which is fast.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -