View difference between Paste ID: n5UXfAZ3 and gAqntZh2
SHOW: | | - or go back to the newest paste.
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Text.RegularExpressions;    
6
7
namespace PandoraBox
8
{
9
    public class MixAndCutPlugin : IPluginMacro
10
    {
11
        public string Execute(string template, PluginMacroArgs args)
12
        {
13
            return Regex.Replace(template, @"\{MIXANDCUT-(\d+)}(.*?){/MIXANDCUT}", m => 
14
            {                                               
15-
                var count = int.Parse(m.Groups[1].Value); //счетчик лежит в 1 параметре макроса
15+
                var count = int.Parse(m.Groups[1].Value); //кол-во лежит в 1 параметре макроса
16
                var innerText = m.Groups[2].Value; //текст лежит в 2 параметре макроса
17
                
18
                var rndWords = innerText 
19
                    .Trim() //во внутреннем тексте обрезаем пробелы
20
                    .Split(' ') //рубим по пробелам
21
                    //.OrderBy(i => Rnd.InnerObject.Next()) //перемешиваем, правда я отключил его, раскомментируйте если надо
22
                    .Where(word => word.Length >= 3) //отфильтровать только слова >= 3 символов
23
                    .Take(count); //взять только нужное число слов
24
                    
25-
                var result = String.Join(" ", rndWords);
25+
                var result = String.Join(" ", rndWords); //соединяем слова в фразу через пробелы
26
                     
27
                //чистка регуляркой 1
28
                result = Regex.Replace(result, @"[^a-zа-я0-9]*$", ""); 
29
                //чистка регуляркой 2
30
                result = Regex.Replace(result, @"\(([^\)\r\n]*)$", "($1)");
31
                
32
                //вывод
33
                return result;
34
            });
35
        }      
36
        public ushort Level { get { return 10; } }
37
        public String Name { get { return "MixAndCutPlugin"; } }
38
    }
39
}