Как выделить текст html тегом, если в нужном месте меньше 10 слов?

backoff

Client
Регистрация
20.04.2015
Сообщения
5 995
Благодарностей
6 444
Баллы
113
помогите решить задачку, имеем исходник, для примера
Delicious Milk: A Guide to All Things Creamy\n\nMilk is a staple ingredient in many dishes, beverages, and desserts. From its creamy texture to its versatile taste, milk is a natural and essential ingredient in many recipes. But not all milk is created equal. Today, we'll be discussing the different types of milk, the benefits of drinking milk, and how to choose the best kind of milk for your needs.\n\n1. Skim Milk vs. Whole Milk: Which One is Better?\n\nSkim milk is a popular option for those who want to cut down on calories and fat. With its low-fat content, skim milk is ideal for those who want a healthier milk option. On the other hand, whole milk is creamier and fuller in taste. For those who want a more indulgent taste, whole milk is the way to go. However, it's essential to consider your health goals and calorie intake before choosing between skim and whole milk.\n\n2. Organic Milk: What You Need to Know\n\nOrganic milk is produced using strict guidelines that prohibit the use of synthetic pesticides, hormones, and antibiotics. Organic milk is an excellent option for those who want to avoid the additives and chemicals that may be found in conventional milk. However, it is crucial to note that organic milk is pricier than regular milk.\n\n3. Lactose-Free Milk: A Solution for Lactose Intolerance\n\nLactose intolerance is a common digestive issue that affects many people. For those who are lactose intolerant, drinking regular milk can cause stomach discomfort and digestive problems. Luckily, lactose-free milk is an alternative that allows people with lactose intolerance to enjoy milk without any negative side effects.

нужно взять все значения, которые находятся между \n и \n
и выделить их нужными тегами, если в найденном значении слов меньше 10 (к примеру)

должно получиться так
<teg>Delicious Milk: A Guide to All Things Creamy</teg>\n\nMilk is a staple ingredient in many dishes, beverages, and desserts. From its creamy texture to its versatile taste, milk is a natural and essential ingredient in many recipes. But not all milk is created equal. Today, we'll be discussing the different types of milk, the benefits of drinking milk, and how to choose the best kind of milk for your needs.\n\n<teg>1. Skim Milk vs. Whole Milk: Which One is Better?</teg>\n\nSkim milk is a popular option for those who want to cut down on calories and fat. With its low-fat content, skim milk is ideal for those who want a healthier milk option. On the other hand, whole milk is creamier and fuller in taste. For those who want a more indulgent taste, whole milk is the way to go. However, it's essential to consider your health goals and calorie intake before choosing between skim and whole milk.\n\n<teg>2. Organic Milk: What You Need to Know</teg>\n\nOrganic milk is produced using strict guidelines that prohibit the use of synthetic pesticides, hormones, and antibiotics. Organic milk is an excellent option for those who want to avoid the additives and chemicals that may be found in conventional milk. However, it is crucial to note that organic milk is pricier than regular milk.\n\n<teg>3. Lactose-Free Milk: A Solution for Lactose Intolerance</teg>\n\nLactose intolerance is a common digestive issue that affects many people. For those who are lactose intolerant, drinking regular milk can cause stomach discomfort and digestive problems. Luckily, lactose-free milk is an alternative that allows people with lactose intolerance to enjoy milk without any negative side effects.
как можно такое реализовать, спасибо
 

backoff

Client
Регистрация
20.04.2015
Сообщения
5 995
Благодарностей
6 444
Баллы
113

Phoenix78

Client
Read only
Регистрация
06.11.2018
Сообщения
11 790
Благодарностей
5 709
Баллы
113

backoff

Client
Регистрация
20.04.2015
Сообщения
5 995
Благодарностей
6 444
Баллы
113
ага, еще бы понимать почему код не работает...
 

Phoenix78

Client
Read only
Регистрация
06.11.2018
Сообщения
11 790
Благодарностей
5 709
Баллы
113

backoff

Client
Регистрация
20.04.2015
Сообщения
5 995
Благодарностей
6 444
Баллы
113
хуйня какая-то получается с юзингом и прочим
 
  • Спасибо
Реакции: Sho

n0n3mi1y

Client
Регистрация
08.03.2017
Сообщения
1 209
Благодарностей
552
Баллы
113
Что ж вы все так не любите сами докапываться до истины?
Никаких юзингов и не надо.


C#:
string input = project.Variables["inputText"].Value;

project.SendInfoToLog(input);
var totalList = new List<string>();
var spl = input.Split(new[] { "\\n" }, StringSplitOptions.RemoveEmptyEntries);
project.SendInfoToLog(spl.Length.ToString());
foreach (string line in spl)
{
    if (line.Length > 0 && line.Split(' ').Length < 10)
    {
        totalList.Add($"<tag>{line}</tag>");
        project.SendInfoToLog($"<tag>{line}</tag>");
    }
    else
    {
        continue;
    }
}

project.Variables["outputText"].Value = string.Join("\n", totalList);
106128
 

Вложения

  • Спасибо
Реакции: Sho

backoff

Client
Регистрация
20.04.2015
Сообщения
5 995
Благодарностей
6 444
Баллы
113
Что ж вы все так не любите сами докапываться до истины?
так уже все сделал, по другому решил задачку, считаю сколько пробелов в строке и все, дальше кубиком замены

но спасибо за сниппет
 

Кто просматривает тему: (Всего: 2, Пользователи: 0, Гости: 2)