Re: subset function for string in c++



Randy Howard wrote:
August Karlstrom wrote
puzzlecracker wrote:

basically, I need to find out wether charecters in string a are subset
of string b..



example



a: rx b:rwx that shall return true.



As this group is language independent i chose to write an implementation in Oberon:


   PROCEDURE Subset(a, b: ARRAY OF CHAR): BOOLEAN;
      VAR j, k: LONGINT;
   BEGIN
      j := 0;
      WHILE a[j] # 0X DO
         k := 0;
         WHILE (b[k] # 0X) & (b[k] # a[j]) DO INC(k) END;
         IF b[k] = 0X THEN RETURN FALSE END;
         INC(j)
      END;
      RETURN TRUE
   END Subset;




Wow. Ben's version sure seems a lot clearer. :-)

Since the original poster wrote to comp.programming I assumed he/she was interested in an algorithm. Otherwise comp.lang.c++ is be the appropriate group to consult.


I'm having pascal flashbacks, make it stop.

The similarities between Pascal and Oberon is mostly at the syntactic level. The two languages are as different as say C and Java.



August .



Relevant Pages

  • Re: Help Setting HTML Color?
    ... function Sto_ColorToHtml: String; ... iHtml: Longint; ... // converts an html color string to a color, ...
    (borland.public.delphi.language.objectpascal)
  • Re: subset function for string in c++
    ... puzzlecracker wrote: ... of string b.. ... VAR j, k: LONGINT; ...
    (comp.programming)
  • Re: subset function for string in c++
    ... puzzlecracker wrote: ... of string b.. ... VAR j, k: LONGINT; ...
    (comp.programming)
  • Re: Calculate the string statement
    ... verkn:(vkn:char; ... funkt:(fkt:string; ... var fkt,dfkt: p; ... var fehler: boolean; ...
    (comp.lang.pascal.borland)
  • Two new tests for MM B&V
    ... var RunningThreads: Integer; ... class function TStringThreadTest.GetBenchmarkDescription: string; ... function CheckPattern(const Dest: Pointer; const Size: Integer; const ...
    (borland.public.delphi.language.basm)