Regular expression to delete lines over a character limit.

  • Автор темы Автор темы JIMBOB
  • Дата начала Дата начала

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
 
Try this refex:
[\w\d]{1,n} where n - number of characters to limit
 
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);
}
 

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