I want compare two string and want to get possible matches [closed] - c#

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
sb.Qualilfication_Master.First().Qual_List contain string values like "B.C.A,M.C.A,B.B.A"
and txtQualification.text contain string like "B.C.A, M.Com"
I want match above two thing
var sendnoti = (from p in db.Reg_JobSeeker_Masters where p.Qualification_Masters.First().Qual_List.Contains(txtQualification.Text)select p).ToList();

If I'm reading this right - and you want to find the strings that are common to two lists - then you can just use the intersect method.

I am just assuming txtQualification.Text is a List<string> so in that case you could just right it like this -
var sendnoti = (from p in db.Reg_JobSeeker_Masters where p.Qualification_Masters.First().Qual_List.Any(ql => txtQualification.Text.Contains(ql))select p).ToList();

Related

Regex to remove c# [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I want to remove some string from regex in c#.
I have a string
000603ABC140702-005051-I-FILL200-NNYYNY180319-142110-A2002.zip
From this I want to remove those strings
140702
142110
And I want a result as
000603ABC-005051-I-FILL200-NNYYNY180319--A2002.zip
How can I do that in regex?
You can use the Regex.Replace method (https://msdn.microsoft.com/en-us/library/xwewhkd1(v=vs.110).aspx).
var regex = new Regex("(140702)|(142110)");
var result = regex.Replace("000603ABC140702-005051-I-FILL200-NNYYNY180319-142110-A2002.zip", "");
Although, as already stated by #CompuChip, String.Replace would probably be more efficient in this case. There's a discussion of various methods of replacing substrings and their efficiency at https://blogs.msdn.microsoft.com/debuggingtoolbox/2008/04/02/comparing-regex-replace-string-replace-and-stringbuilder-replace-which-has-better-performance/.

Predicate matching a list [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I'm trying to do something like -
List<int> accountList = new List<int>();
accountList .Add(1);
accountList .Add(27);
var rec = _db.Accounts.Where(a=> accountList.Contains(a.accountId)).Take(10);
My code is a little more complicated than this - there are several other conditions in the where clause, but this is the bit that is causing problems - nothing gets returned even when there are matching values.
Basically I want it to retrieve all the records where accountId matches a value in my list.
Any pointers?
The sample above is giving me a cant convert lambda error.
You are missing a bit on your contains version
var hold2 = _db.Accounts.Where(a => find.Contains(a.accountDd)).Take(10).ToList();
Have you tried using any
var hold2 = _db.Accounts.Where(a => accountList.Any(m => m == a.accountId)).Take(10).ToList();

How to find __tokens__ in a string without using RegEx in C# [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I have the following:
The __animal__ jumped over the __object__
I'd like to write a concise method in C# that returns animal and object. How can this be done without RegEx? A dirty solution would be to iterate through the characters one by one until we find a __ and then build a string until we find the closing __ - but I'm looking for a more elegant approach.
You are going to have to iterate in some form - if you don't want to use regex.
string text = "The __animal__ jumped over the __object__";
List<string> words = text.Split(' ').ToList();
words = words.Where(x => x.StartsWith("__") && x.EndsWith("__")).ToList();
You can use extensions of IEnumerable.to search, like above. but the framework is technically iterating.

String Contains Does Not Work In LINQ [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I've always used Contains method to gain SQL IN functionality to my LINQ queries.
But this time, very strange thing occured.
I've got an array of string like this :
string[] FilenamesToParse = {"JOHN_X200-", "DOE_X300-", "FOO_X300_M-"};
Then I've used this array just like below:
var result = (from dps in appProcessList
where FilenamesToParse.Contains(dps.FileName)
select dps.Devices).ToList()
Above query resulted with 0 result but I'm sure that there are filenames contains words defined in FilenamesToParse array.
So I've tried below snippet and Contains worked.
foreach (var applicationProcess in appProcessList)
{
if (applicationProcess.FileName.Contains(FilenamesToParse[0]))
{
}
}
Where am I wrong here ?
Thanks in advance.
Your two appraoches aren´t similar. In your linq you´re iterating your FilenamesToParse-array and check if any of its elements exactly matches dps.FileName, whereby in the second one you iterate appProcessList and check if its FileName-property contains the first FilenamesToParse.
The following would be the linq-approach similar to your loop:
var result = (from dps in appProcessList
where FilenamesToParse.Any(x => dps.FileName.Contains(x))
select dps.Devices).ToList()

Compare two comma separated string and find the missing values [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
Which is the best way I can compare two C# string variables containing comma separated values and find the difference?
The scenario is like.
string variable1 = "AAA, BBB, CCC, DDD";
string variable2 = "AAA, CCC, DDD, EEE";
And I need the result like "BBB" (the value which is present in variable2 but not in variable1.
Thanks
Use Except:-
var result = variable1.Split(new char[] {','})
.Except(variable2.Split(new char[] {','})).ToArray();

Categories