Regular expression to delete lines over a character limit.

JIMBOB

Пользователь
Регистрация
07.04.2022
Сообщения
35
Благодарностей
0
Баллы
6
Hello

I wasn't sure if this was the right place to post this but I have a list where I want to delete any lines that are over a specific character limit.

I'm not really sure if using a regex is the right way to go about it but I can't seem to find another way to do it.

Anyone have any ideas how to create the regex to do it?

90985


Thank you
 

VladZen

Administrator
Команда форума
Регистрация
05.11.2014
Сообщения
22 415
Благодарностей
5 900
Баллы
113
Try this refex:
[\w\d]{1,n} where n - number of characters to limit
 

EtaLasquera

Client
Регистрация
02.01.2017
Сообщения
526
Благодарностей
112
Баллы
43
I think you need to check length of every line and after check all lines, delete what you want.

I think something like this....

var lst = project.Lists["myList"];
List<int> deletelines = new List <int> ();
for (int i = 0; i < lst.Count(); i++){
string s = lst;
if (s.Length() > 40){
deletelines.Add(i);
}
}

deletelines.Reverse();
foreach (int d in deletelines){
lst.RemoveAt(d);
}
 

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