D
D
Dominik092016-07-10 22:17:00
C++ / C#
Dominik09, 2016-07-10 22:17:00

How to remove extra spaces in RichTextBox without resetting formatting?

I remove unnecessary problems with the following command:

RichTextBox.Text = Regex.Replace(RichTextBox.Text, "[ ]+", " ");

The program successfully removes unnecessary problems, but the problem is that after that it completely resets the formatting. For example, before deletion, the text was located on the right edge of the text, and then it moves to the left edge. Here it is clear that it is simply not necessary to assign the result. I tried to do through the loop symbolically, but it doesn't work.
bool onespace = false;
            for (int i = 0; i < RichTextBox.TextLength; i++)
            {
                if (RichTextBox.Text[i] == ' ')
                {
                    //если перед этим тоже был пробел..
                    if (onespace )
                    {
                        RichTextBox.Text.Remove(i);                      
                    }
                    else
                        onespace = true;
                }
                else
                    onespace = false;
            }

How to remove extra spaces in a RichTextBox so that formatting is not reset?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
#
#algooptimize #bottize, 2016-07-10
@user004

RichTextBox.Rtf
Not sure what happens...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question