N
N
Newmo2019-10-23 17:15:14
C++ / C#
Newmo, 2019-10-23 17:15:14

How to cut a piece of text from end to start?

There is a document in which there are many articles. It is known that after some technical information comes the title of the post (bold). It ends with the username highlighted in red.
I need to find the name, I find it like this:

{
            //Читаем активный файл на наличие вхождений
            object findText = surname.Text;
            //Сбрасываем форматирование
            Globals.ThisAddIn.Application.Selection.Find.ClearFormatting();
            //Производим поиск только в строках с красными буквами
            Globals.ThisAddIn.Application.Selection.Find.Font.ColorIndex = Word.WdColorIndex.wdRed;
            if (Globals.ThisAddIn.Application.Selection.Find.Execute(ref findText))
            {
                MessageBox.Show("Нашел");

            }
            else
            {
                MessageBox.Show("Не нашел.");
            }
        }

Help me figure out how to now find the preceding bold title and select all text (wdStory) from the bold title to the red username...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Newmo, 2019-10-24
@Newmo

Everything turned out to be simple:
Find.Text.Forward:
true - search down
false - search up.

B
BasiC2k, 2019-10-23
@BasiC2k

VSTO is a good thing...
Search by text color. Remember the position of the found character, look further. Find. Cutting test from... to... etc.
Read about the Word object model. It is a bit difficult to understand right away, but then it will be easier for you to implement your plan.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question