How to get intersection of two strings in C#

1 Answer

0 votes
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        string str1 = "php";
        string str2 = "python";

        // Find the intersection of characters
        var intersection = new string(str1.Intersect(str2).ToArray());

        Console.WriteLine($"Intersection: {intersection}");
    }
}



/*
run:

Intersection: ph

*/

 



answered Jul 6, 2025 by avibootz
...