Answer the question
In order to leave comments, you need to log in
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("Не нашел.");
}
}
Answer the question
In order to leave comments, you need to log in
Everything turned out to be simple:
Find.Text.Forward:
true - search down
false - search up.
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 questionAsk a Question
731 491 924 answers to any question