Re: subset function for string in c++



Randy Howard wrote:
August Karlstrom wrote
(in article <XSE_e.147284$dP1.504155@xxxxxxxxxxxxxxx>):


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.


I was making a comment on the wordiness of Oberon, not on what language the solution was in, and it was mostly tongue in cheek. I would expect a modern language to have a bit more in the way of standard string support and not have to roll it from scratch, or is there a more direct way of doing it with Oberon builtins?

Oberon is an efficient minimalist language. The inclusion of standard string support would introduce "hidden costs" (and make the language larger). There is a module (Strings) in the standard library though that provides some basic string procedures.



August .



Relevant Pages

  • Re: Operator overloading in C
    ... All development of C as an independent language has ... making any changes or improvements to the standard ... The lack of a counted string data structure, ... Pointers can't be used for arg1 or arg2. ...
    (comp.std.c)
  • Re: syntax...
    ... B&D on the part of the language designer. ... probably handle concatenation of string literals by itself, ... bitwise XOR, or if not that, then exponentiation.) ...
    (comp.lang.misc)
  • Why C Is Not My Favourite Programming Language
    ... C has no string type. ... compiler take care of the rest. ... Why does any normal language ... the programmer fail. ...
    (comp.lang.c)
  • Re: Controlling Javascript from server side
    ... but five different language implementations here. ... 'true' means that the request must be handled asynchronously. ... There is exactly *no* reason for such a thing here. ... | percent-endoded string). ...
    (comp.lang.javascript)
  • Re: Theodore Adorno, a prophet of data systems design
    ... C may not be a forgiving language, ... >> attention get burned with the memory leaks, and buffer overruns, ... by a small, compact team of brilliant programmers, or it may be ... so you agree that it is not a limit on the length of the string, ...
    (comp.programming)