Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
1.00/5 (5 votes)
See more:
Suppose I have a string A = "A,B,C" and a string B = "C,D,E". I am looking for a quick system that tells me which words in B are not contained in A. In this case C = "D,E". I have already made a function that searches through indexOf but I ask if there is a faster Regex system or whatever. I would also like to know if there are any known string handling C# function libraries and even if it can be maintained between multiple people.

What I have tried:

in all sites.in all sites.in all sites.
Posted
Updated 3-Oct-21 2:30am
Comments
BillWoodruff 2-Oct-21 9:11am    
Come back, when you have tried something, with specific questions. If we do your homework you will learn nothing.
Member 14890678 2-Oct-21 9:15am    
yes sir, whatever you say.
BillWoodruff 3-Oct-21 5:21am    
give me fifty push-ups :) ... try to figure out why this post has four downvotes.
PIEBALDconsult 2-Oct-21 10:00am    
Split A into an array.
Split B into an array and create a Hashset with it.
Use HashSet.ExceptWith to remove A from B.
Member 14890678 2-Oct-21 12:06pm    
Is that the origin is the string. I already have a system that uses indexOf. If I pass the chain to Hashet I spend time and it is what I do not want.

1 solution

Break the strings into separate words in arrays or other collections, and then just use Linq methods. It's one line of code:
C#
string A = "A,B,C";
string B = "C,D,E";
var items = A.Split(',').Except(B.Split(','));
Console.WriteLine(string.Join(", ", items));
 
Share this answer
 
Comments
PIEBALDconsult 2-Oct-21 10:07am    
You may have that backward.
OriginalGriff 2-Oct-21 10:28am    
Homework should involve some user effort (particularly if the code is going to be obviously copied :D )
Member 14890678 2-Oct-21 12:03pm    
Does anyone know where there are people who run a chain treatment and linguistic library? I have many functions done by me but I would like to see what people do.
Member 14890678 3-Oct-21 8:31am    
IS THE CORRECT SOLUTION:
string A = "A,B,C";
string B = "C,D,E";
var items = B.Split(',').Except(A.Split(','));

BUT:
One thing happens:However, it is necessary to be able to make the function not take into account capital letters or accents.
OriginalGriff 3-Oct-21 9:11am    
And?
What have you done about that?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900