Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,845 questions

51,766 answers

573 users

How to get intersection of two strings in Pascal

1 Answer

0 votes
program StringIntersection;

function GetIntersection(const Str1, Str2: string): string;
var
  i: Integer;
  CommonChars: string;
begin
  CommonChars := '';
  for i := 1 to Length(Str1) do
  begin
    if (Pos(Str1[i], Str2) > 0) and (Pos(Str1[i], CommonChars) = 0) then
      CommonChars := CommonChars + Str1[i];
  end;
  GetIntersection := CommonChars;
end;

var
  String1, String2, Intersection: string;
begin
  String1 := 'php';
  String2 := 'python';
  
  Intersection := GetIntersection(String1, String2);
  
  WriteLn('Intersection of "', String1, '" and "', String2, '" is: "', Intersection, '"');
end.

  
  
(*
run:
 
Intersection of "php" and "python" is: "ph"
 
*)

 



answered Jul 6, 2025 by avibootz
...