- Регистрация
- 13.01.2009
- Сообщения
- 2 285
- Благодарностей
- 2 730
- Баллы
- 113
These samples can be useful solving common tasks of searching in lists and tables
Search inlists:
Task 1.
There is a list, where we need find all elements that mach regular expression and put them to another list.
You can use this C# macro for that (in the attached project, we go through all domains from the list and select ones that contain digitals)
Task 2.
There is a list, where we need check a text presence
It can be solved using this C# macro (in the attached project, we go through all domains from the list and check if domain contains ".jp")
Search in tables:
Task 1
There is a table, we ned select rows, that suit search criteria and put them to another table.
It can be solved using this C# macro (in the attached project, we are searching for people whose jobs related with sales)
Task 2
We need to check if there is a cell that contains a specific text.
It can be solved using this C# macro (in the attached project, we are searching a cell that contains "Mexico")
Search inlists:
Task 1.
There is a list, where we need find all elements that mach regular expression and put them to another list.
You can use this C# macro for that (in the attached project, we go through all domains from the list and select ones that contain digitals)
JavaScript:
// 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);
}
}
}
Task 2.
There is a list, where we need check a text presence
It can be solved using this C# macro (in the attached project, we go through all domains from the list and check if domain contains ".jp")
JavaScript:
// take search text from variable
var textContains = project.Variables["listSearchTextContains"].Value;
// get a list or search
var sourceList = project.Lists["SourceList"];
// search in each line of list
lock(SyncObjects.ListSyncer)
{
for(int i=0; i < sourceList.Count; i++)
{
// get line from list
var str = sourceList[i];
// check if line contains text, if there are matches return "yes"
if (str.Contains(textContains))
return "yes";
}
}
// ifnothing found return "no"
return "no";
Search in tables:
Task 1
There is a table, we ned select rows, that suit search criteria and put them to another table.
It can be solved using this C# macro (in the attached project, we are searching for people whose jobs related with sales)
JavaScript:
// take regex for parsing from a variable
var parserRegexPattern = project.Variables["tableSearchRegex"].Value;
var parserRegex = new System.Text.RegularExpressions.Regex(parserRegexPattern);
// get a table where we search
var sourceTable = project.Tables["SourceTable"];
// get result table
var destTable = project.Tables["OutputTable"];
// search in each row
lock(SyncObjects.TableSyncer)
{
for(int i=0; i < sourceTable.RowCount; i++)
{
// read a row (array of cells)
var cells = sourceTable.GetRow(i).ToArray();
// check the second row if it matches a regex, if there are matches we put it to result table
if (parserRegex.IsMatch(cells[1]))
destTable.AddRow(cells);
}
}
Task 2
We need to check if there is a cell that contains a specific text.
It can be solved using this C# macro (in the attached project, we are searching a cell that contains "Mexico")
JavaScript:
// take text for search from a variable
var textContains = project.Variables["tableSearchTextContains"].Value;
// get table for search
var sourceTable = project.Tables["SourceTable"];
// search in each row
lock(SyncObjects.TableSyncer)
{
for(int i=0; i < sourceTable.RowCount; i++)
{
// read a row (array of cells)
var cells = sourceTable.GetRow(i).ToArray();
// loop through all cells
for (int j=0; j < cells.Length; j++)
{
// check if cell contains specified text, if there are matches return "yes"
if (cells[j].Contains(textContains))
return "yes";
}
}
}
// if nothing found return "no"
return "no";
Вложения
-
39,4 КБ Просмотры: 873