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

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

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

Disclosure: My content contains affiliate links.

43,401 questions

56,365 answers

573 users

How to remove characters present in first string from the second string in Pascal

2 Answers

0 votes
program RemoveCharactersDemo;

{$mode objfpc}{$H+}

uses
  SysUtils;

type
  TCharSet = set of Char;

function RemoveCharacters(const Source, CharsToRemove: string): string;
var
  Forbidden: TCharSet;
  Ch: Char;
begin
  Forbidden := [];

  { Build a lookup set of characters to remove }
  for Ch in CharsToRemove do
    Include(Forbidden, Ch);

  Result := '';

  { Keep only characters not present in the set }
  for Ch in Source do
    if not (Ch in Forbidden) then
      Result := Result + Ch;
end;

var
  First, Second: string;
begin
  First := 'programming language';
  Second := 'rogy';

  WriteLn('First : "', First, '"');
  WriteLn('Second: "', Second, '"');
  WriteLn('Result: "', RemoveCharacters(Second, First), '"');
end.



{
run:

First : "programming language"
Second: "rogy"
Result: "y"

}

 



answered 2 days ago by avibootz
0 votes
program RemoveCharactersDemo;

{$mode objfpc}{$H+}

uses
  SysUtils;

type
  TCharSet = set of Char;

// For larger strings
function RemoveCharacters(const Source, CharsToRemove: string): string;
var
  Forbidden: TCharSet;
  Ch: Char;
  I: Integer;
begin
  Forbidden := [];

  for Ch in CharsToRemove do
    Include(Forbidden, Ch);

  SetLength(Result, Length(Source));
  I := 0;

  for Ch in Source do
    if not (Ch in Forbidden) then
    begin
      Inc(I);
      Result[I] := Ch;
    end;

  SetLength(Result, I);
end;

var
  First, Second: string;
begin
  First := 'programming language';
  Second := 'rogy';

  WriteLn('First : "', First, '"');
  WriteLn('Second: "', Second, '"');
  WriteLn('Result: "', RemoveCharacters(Second, First), '"');
end.



{
run:

First : "programming language"
Second: "rogy"
Result: "y"

}

 



answered 2 days ago by avibootz

Related questions

...