C# to find out all the lines contain "33"

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

spyder

Client
Регистрация
19.10.2014
Сообщения
27
Реакции
1
Баллы
3
hi, guys,
i have a list as below:
11a
22b
33c
44d
55e
33f

how to use C# to find out all the lines contain "33", and put the line numbers to List2 ?

[i know that i can take one line, then use REG to check it contains value or not.
BUT, cause i have many lines. it will take too long time to check line one by one.]

anyone knows how to use C# to do it ?

thank you very much.
 
hi, lokiys
thanks for the treads. it do help me a lot. but it save the line value, and i want to save the lines count.
according to the threads, it will save :
33c
33f
but i want to save the
2 //"33c" is on the 2nd line
5 //"33f" is on the fifth line

how to edit it the code, please ?

Код:
Развернуть Свернуть Копировать
// prepare regular expression for parsing
var parserRegexPattern = project.Variables["listSearchRegex"].Value;
var parserRegex = new System.Text.RegularExpressions.Regex(parserRegexPattern);
// get a list for searching
var sourceList = project.Lists["SourceList"];
// get result list
var destList = project.Lists["OutputList"];
// search in each line of the list
lock(SyncObjects.ListSyncer)
{
    for(int i=0; i < sourceList.Count; i++)
    {
        // take one line from the list
        var str = sourceList[i];
        // check the line on matches by regex, if there are matches we put it to result list
        if (parserRegex.IsMatch(str))
        {
            destList.Add(str);       
        }
    }
}
 
i got it. hahah,
Код:
Развернуть Свернуть Копировать
// prepare regular expression for parsing
var parserRegexPattern = project.Variables["listSearchRegex"].Value;
var parserRegex = new System.Text.RegularExpressions.Regex(parserRegexPattern);
// get a list for searching
var sourceList = project.Lists["SourceList"];
// get result list
var destList = project.Lists["OutputList"];
// search in each line of the list
lock(SyncObjects.ListSyncer)
{
    for(int i=0; i < sourceList.Count; i++)
    {
        // take one line from the list
        var str = sourceList[i];
        // check the line on matches by regex, if there are matches we put it to result list
        if (parserRegex.IsMatch(str))
        {
            destList.Add("" +i );     
        }
    }
}
 
  • Спасибо
Реакции: Radzhab

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