Добавил еще ведущие нули к миллисекундам, если кому-то еще когда-то этот код понадобится
log = function (text, color, define){ var id, time, thread, logHtml, textLog; define = (typeof define == 'string') ? define.split(/[\s,.|:;]+/g) : define; if(typeof define === 'object' && define !== null){ if(Array.isArray(define)){ id = define.indexOf('id') > -1; time = define.indexOf('time') > -1; thread = define.indexOf('thread') > -1; } else{ id = define.id == true; time = define.time == true; thread = define.thread == true; } } else id = time = thread = true; id = id ? '<a href="action://action' + ScriptWorker.GetCurrentAction() + '" style="color:gray;">[' + ScriptWorker.GetCurrentAction() + ']</a>' : ''; time = time ? ' ' + getTime() : ''; thread = thread ? ' Поток №' + thread_number() : ''; logHtml = (id || time || thread) ? id + '<span style="color: white">' + time + thread + ' : </span>' : ''; logHtml += '<span style="color:' + (color ? color : 'white') + '">' + text + '</span>'; textLog = '[' + ScriptWorker.GetCurrentAction() + ']' + time + thread + ' : ' + text function getTime(){ var checkTime = function(i){ return (i < 10) ? "0" + i : i; }; var checkMilliSeconds = function(ms){ if (ms < 10) { return "00" + ms; } else if (ms < 100) { return "0" + ms; } else { return ms; } }; var d = new Date(); var hh = checkTime(d.getHours()); var mm = checkTime(d.getMinutes()); var ss = checkTime(d.getSeconds()); var ms = checkMilliSeconds(d.getMilliseconds()); return '[' + hh + ':' + mm + ':' + ss + '.' + ms + ']'; }; Logger.WriteHtml(logHtml, textLog); }Как в списке удалить весь текст выше 3-рёх подряд строк заканчивающихся на знаки препинания в конце?
-
Есть переменная [[LIST_WITH_FILE_CONTENT]] в ней много строчек.
Подскажите, как с помощью JS удалить в нём все строки что выше 3-рёх подряд идущих строк.
В конце этих 3-рёх строк должны стоять символы из списка [[SYMBOLS]] .
В списке [[SYMBOLS]] находятся знаки препинания:
. , ! ? " ' : ” “Пример [[LIST_WITH_FILE_CONTENT]] :
Or to take arms against a sea of troubles? And by opposing end them. To die—to sleep No more; and by a sleep to say we end. The heart-ache and the thousand natural shocks That flesh is heir to: ’tis a consummation! Devoutly to be wish’d. To die, to sleep; To sleep, perchance to dream—ay, there’s the rub: For in that sleep of death what dreams may come Borne on the bier6 with white and bristly beard: Then of thy beauty do I question makeДолжно остаться так (выделил красной рамкой):

Написал JS-код для экшена Яваскрипт:const str = [[LIST_WITH_FILE_CONTENT]]; const punct = [[SYMBOLS]]; const numStrWithPunctEnd = 3; const arr = str.split('\n'); const index = arr.findIndex(function(n, i, a) { return this.every(m => punct.includes(a[i + m].slice(-1))); }, [...Array(numStrWithPunctEnd).keys()]); const result = index !== -1 ? arr.slice(index).join('\n') : str; [[LIST_WITH_FILE_CONTENT]]=result;Но почему выдаёт ошибку:

-
@Nikolas said in Как в списке удалить весь текст выше 3-рёх подряд строк заканчивающихся на знаки препинания в конце?:
Есть переменная [[LIST_WITH_FILE_CONTENT]] в ней много строчек.
Подскажите, как с помощью JS удалить в нём все строки что выше 3-рёх подряд идущих строк.Скажите, для чего вы каждую задачу пытаетесь решить через js скрипты не разбираясь в них совсем? Чем вам кубики BAS'a не угодили?
-
Вот готовый код, может кому-то будет полезно.
Переменные [[LIST_WITH_FILE_CONTENT]]
и [[SYMBOLS]] естественно до этого должны быть заданы.Код закидываем в экшен Яваскрипт:
let arr = [[LIST_WITH_FILE_CONTENT]]; const punct = [[SYMBOLS]]; const numStrWithPunctEnd = 3; const index = arr.findIndex(function(n, i, a) { return this.every(m => punct.includes(a[i + m].slice(-1))); }, [...Array(numStrWithPunctEnd).keys()]); const result = index !== -1 ? arr.slice(index).join('\n') : arr; [[LIST_WITH_FILE_CONTENT]]=result;Получаем результат в виде строки в переменной [[LIST_WITH_FILE_CONTENT]].
Далее , пишем данные из [[LIST_WITH_FILE_CONTENT]] в файл с помощью экшена Запись в файл-> далее следующим экшеном -> Читать файл в список. Таким образом получаем готовый результат уже в виде списка в переменной [[LIST_WITH_FILE_CONTENT]]