why this c# code doesnot work?

Besedi

Client
Регистрация
04.03.2019
Сообщения
234
Благодарностей
40
Баллы
28
var list1 = project.Lists["list"];
var list2 = project.Lists["list1"];
foreach (string element1 in list1)
{
foreach (string element2 in list2)
{
if (element1.Contains(element2))
{
project.Lists["l4"].Add(element1);
}
}
}
Got empty list, in VisualStudio it's works:

var list1= new List<string>() { "line1", "line2" };
var list2 = new List<string>() { "e1", "e2" };

foreach (string element1 in list1)
{
foreach (string element2 in list2)
{
if (element1.Contains(element2))
{
Console.WriteLine("contains");
Console.ReadLine();
}
}
}
 

BAZAg

Client
Регистрация
08.11.2015
Сообщения
1 765
Благодарностей
2 407
Баллы
113
var list1 = project.Lists["list"];
var list2 = project.Lists["list1"];
foreach (string element1 in list1)
{
foreach (string element2 in list2)
{
if (element1.Contains(element2))
{
project.Lists["l4"].Add(element1);
}
}
}
Got empty list, in VisualStudio it's works:

var list1= new List<string>() { "line1", "line2" };
var list2 = new List<string>() { "e1", "e2" };

foreach (string element1 in list1)
{
foreach (string element2 in list2)
{
if (element1.Contains(element2))
{
Console.WriteLine("contains");
Console.ReadLine();
}
}
}
C#:
List<string> list = project.Lists["list"].ToList<string>();
// add demo data list
list.Add( "line1");
list.Add(  "line2");

List<string> list1 = project.Lists["list1"].ToList<string>();
// add demo data list1
list1.Add( "e1");
list1.Add(  "e2");

IZennoList list4 = project.Lists["l4"]; // list result

foreach (string s1 in list) {
    foreach (string s2 in list1) {
        if (s1.Contains(s2)) list4.Add(s1);
    }
}
92497
 
  • Спасибо
Реакции: Besedi

Besedi

Client
Регистрация
04.03.2019
Сообщения
234
Благодарностей
40
Баллы
28
C#:
List<string> list = project.Lists["list"].ToList<string>();
// add demo data list
list.Add( "line1");
list.Add(  "line2");

List<string> list1 = project.Lists["list1"].ToList<string>();
// add demo data list1
list1.Add( "e1");
list1.Add(  "e2");

IZennoList list4 = project.Lists["l4"]; // list result

foreach (string s1 in list) {
    foreach (string s2 in list1) {
        if (s1.Contains(s2)) list4.Add(s1);
    }
}
Посмотреть вложение 92497
Don't work properly, maybe it's happen cause list have 10k strings? This method processing only a few string, a lot of data is lost. It should be 5k strings from 10k result, but getting just 26 strings. Or, how can I add strings in bulk from list.project to var in c# cube?
 
Последнее редактирование:

BAZAg

Client
Регистрация
08.11.2015
Сообщения
1 765
Благодарностей
2 407
Баллы
113
Don't work properly, maybe it's happen cause list have 10k strings? This method processing only a few string, a lot of data is lost. It should be 5k strings from 10k result, but getting just 26 strings. Or, how can I add strings in bulk from list.project to var in c# cube?
Apparently I misunderstood the problem.
You wrote that the code does not run correctly in Zennoposter, but it does work well in Visual Studio.
I took your code, inserted the demo data and see that the code is executed correctly, as it should be executed - it checks if there is a substring from the second list in the line from the first list, and if it finds one, then it adds to the third list the line in which the check for the presence of a string from the second list.
Probably Google translator will distort the context of my message.
If your problem persists, try to describe in more detail what exactly you want the code to do.
 
  • Спасибо
Реакции: Besedi

Besedi

Client
Регистрация
04.03.2019
Сообщения
234
Благодарностей
40
Баллы
28
C#:
List<string> list = project.Lists["list"].ToList<string>();
// add demo data list
list.Add( "line1");
list.Add(  "line2");

List<string> list1 = project.Lists["list1"].ToList<string>();
// add demo data list1
list1.Add( "e1");
list1.Add(  "e2");

IZennoList list4 = project.Lists["l4"]; // list result

foreach (string s1 in list) {
    foreach (string s2 in list1) {
        if (s1.Contains(s2)) list4.Add(s1);
    }
}
Посмотреть вложение 92497
Don't work properly, maybe it's happen cause list have 10k string?
Apparently I misunderstood the problem.
You wrote that the code does not run correctly in Zennoposter, but it does work well in Visual Studio.
I took your code, inserted the demo data and see that the code is executed correctly, as it should be executed - it checks if there is a substring from the second list in the line from the first list, and if it finds one, then it adds to the third list the line in which the check for the presence of a string from the second list.
Probably Google translator will distort the context of my message.
If your problem persists, try to describe in more detail what exactly you want the code to do.
So, in digits:
I have 'emails' and 'domains' name lists. 'Emails' list much more than second one. I would like to add string to new list if current string in 'emails' list contain in 'domains', in other words, if domain exist in emails - allow to adding these emails with this domain to new list.

Sample:

emails list:
[email protected]
[email protected]
[email protected]

domains list:
zennolab.com
gmail.com

result list:
[email protected]
[email protected]

With your sample, it works, but If i comment strings with 'list.add' result list is empty, if I added 2 records like in your sample it works and I get 22 other emails, but must be something much more, in this case, cause my 'domains' list have much more strings than 22, and 'emails' have this domains, previosly it was a one list before separate with regex '(?<=@).*'

Sorry that steal your time with disinformation earlier.

Idea in pseudocode:
foreach (string email in emails) {
foreach (string domain in domains) {
if (email.Contains(domain)) result.Add(email);
}
}

I was learning other variants, founnd method .Find but can't implement him in zenno :(
 
Последнее редактирование:

BAZAg

Client
Регистрация
08.11.2015
Сообщения
1 765
Благодарностей
2 407
Баллы
113
1. Create lists in a template. Link them to files. Screenshot example.
92522

92523

92524



C#:
// We take these lists
IZennoList emails = project.Lists["emails"];
IZennoList domains = project.Lists["domains"];
IZennoList result = project.Lists["result"];

// find email
foreach (string email  in emails) {  
    foreach (string domain in domains) {
        if (email.Contains(domain.Trim())) result.Add(email);
    }
}
The result is found as required.

92525


Don't work properly, maybe it's happen cause list have 10k string?
Even if there are 100k lines - this should not be a problem - it will just take more time to search.
 
Последнее редактирование:
  • Спасибо
Реакции: Besedi

Besedi

Client
Регистрация
04.03.2019
Сообщения
234
Благодарностей
40
Баллы
28
1. Create lists in a template. Link them to files. Screenshot example.
Посмотреть вложение 92522
Посмотреть вложение 92523
Посмотреть вложение 92524


C#:
// We take these lists
IZennoList emails = project.Lists["emails"];
IZennoList domains = project.Lists["domains"];
IZennoList result = project.Lists["result"];

// find email
foreach (string email  in emails) {
    foreach (string domain in domains) {
        if (email.Contains(domain.Trim())) result.Add(email);
    }
}
The result is found as required.

Посмотреть вложение 92525



Even if there are 100k lines - this should not be a problem - it will just take more time to search.
Finally, have:
IZennoList emails = project.Lists["emails"];
IZennoList domains = project.Lists["domains"];
IZennoList result = project.Lists["result"];
IZennoList tmp = project.Lists["tmp"];

// find email
foreach (string email in emails) {
foreach (string domain in domains) {
if (email.Contains(domain)) {
if (tmp.Contains(domain)) {
continue;
}
result.Add(email);
tmp.Add(domain);
}
}
}
Works. But some string have multiple condition, I clean these strings with cube "clear duplicates".
Where I can read more about these techniques in C#? Why I need initiate IzennoList, save all list to files with these flags that you show on screenshot.
 

BAZAg

Client
Регистрация
08.11.2015
Сообщения
1 765
Благодарностей
2 407
Баллы
113
Good!
But some string have multiple condition, I clean these strings with cube "clear duplicates".
Example of removing duplicates:
IZennoList result = project.Lists["result"];

// temp tist
List<string> list_data = new List<string>();
// add temp dublicate lines
list_data.Add("[email protected]");
list_data.Add("[email protected]");
list_data.Add("[email protected]");

list_data = list_data.Distinct<string>().ToList(); // delete duplicate

result.AddRange(list_data); // add good data to list result
Where I can read more about these techniques in C#?
Documentation from C# List: https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1?view=netframework-4.5.2

Why I need initiate IzennoList, save all list to files with these flags that you show on screenshot.
I thought that maybe the code is running, but the lists do not contain data. Because of what, I advised you to link lists to files to see if the data is really there.
 
  • Спасибо
Реакции: Besedi

Besedi

Client
Регистрация
04.03.2019
Сообщения
234
Благодарностей
40
Баллы
28
"\domains.txt file associated with a list or table, this may cause problems in operation. For files linked to lists and tables, use the appropriate tools. "
How to avoid this warning in ZennoPoster? Works in ProjectMaker(but spend a lot of time to update files), in Zenno have trouble ((
This error(above) arises from the fact that I am writing data from a list inside the project to a file. Otherwise, result list contain 1 email. I tried to pause, but it did not help, the file is not updated properly.
I thought that maybe the code is running, but the lists do not contain data. Because of what, I advised you to link lists to files to see if the data is really there.
I linked files but it isn't work properly. Otherwise, if lists unlinked it does not work generally.
 

BAZAg

Client
Регистрация
08.11.2015
Сообщения
1 765
Благодарностей
2 407
Баллы
113
"\domains.txt file associated with a list or table, this may cause problems in operation. For files linked to lists and tables, use the appropriate tools. "
How to avoid this warning in ZennoPoster? Works in ProjectMaker(but spend a lot of time to update files), in Zenno have trouble ((
This error(above) arises from the fact that I am writing data from a list inside the project to a file. Otherwise, result list contain 1 email. I tried to pause, but it did not help, the file is not updated properly.

I linked files but it isn't work properly. Otherwise, if lists unlinked it does not work generally.
C#:
lock(SyncObjects.ListSyncer) {
 // your code read-write list
}
 

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