Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

subset function for string in c++

0 views
Skip to first unread message

puzzlecracker

unread,
Sep 28, 2005, 2:02:17 PM9/28/05
to
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.

Ben Pfaff

unread,
Sep 28, 2005, 2:12:05 PM9/28/05
to
"puzzlecracker" <irons...@gmail.com> writes:

/* Returns true if A is a subset of B, false otherwise. */
bool
is_subset (const char *a, const char *b) {
return a[strspn (a, b)] == '\0';
}
--
"Writing is easy.
All you do is sit in front of a typewriter and open a vein."
--Walter Smith

August Karlstrom

unread,
Sep 28, 2005, 4:08:42 PM9/28/05
to

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;


August

Duane Bozarth

unread,
Sep 28, 2005, 5:30:50 PM9/28/05
to

Or,

' Returns true if A is a subset of B, false otherwise.
Function is_subset(a As String, b As String) As Boolean
is_subset = InStr(a, b) > 0
End Function

or, then again,

logical function is_subset(string, substr) result(flg)
character (len=*) :: string, substr

flg = index(string,substr)>0
end function

:)

Randy Howard

unread,
Sep 28, 2005, 5:42:14 PM9/28/05
to
August Karlstrom wrote
(in article <eLC_e.34873$d5.1...@newsb.telia.net>):

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

I'm having pascal flashbacks, make it stop.

--
Randy Howard (2reply remove FOOBAR)

puzzlecracker

unread,
Sep 28, 2005, 6:03:08 PM9/28/05
to


All above is NOT- again NOT NOT NOT NOT C++...


the c++ way is - are you all still with me (pay attention... NOW)?

string a; // that is right, here we declare a string and named it a
string b; // same as above

// give some values to a and b...like

a="why cannot I still write c++ code";
b="c++ code";

a.find_first_not_of(b);

That is what we call sleek C++ code in the UNITED STATES OF AMERICA!

Now, re-read it 100 times and admit that above posts are flawed,
erronous, completely bizzare and ultimately useless.

we rule,

puzzlecracker.

Ben Pfaff

unread,
Sep 28, 2005, 6:26:59 PM9/28/05
to
"puzzlecracker" <irons...@gmail.com> writes:

> All above is NOT- again NOT NOT NOT NOT C++...

Well, no, the Oberon code you quoted is not C++. It wasn't
claimed to be.

[...]
> we rule,

It's good to know that you have high self-esteem, but I wonder
whether it's really justified.
--
"Long noun chains don't automatically imply security."
--Bruce Schneier

August Karlstrom

unread,
Sep 28, 2005, 6:33:27 PM9/28/05
to
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

August Karlstrom

unread,
Sep 28, 2005, 6:38:20 PM9/28/05
to

*PLONK*

Randy Howard

unread,
Sep 28, 2005, 6:48:21 PM9/28/05
to
puzzlecracker wrote
(in article
<1127944988.5...@g43g2000cwa.googlegroups.com>):

>>
>> Wow. Ben's version sure seems a lot clearer. :-)
>>
>> I'm having pascal flashbacks, make it stop.
>>
>> --

> All above is NOT- again NOT NOT NOT NOT C++...

Duh. I don't recall anyone claiming it was. I think the "an
implementation in Oberon" part clued most of us in to that fact
immediately, if not for the code that followed.

> the c++ way is - are you all still with me

No, not really.

> // give some values to a and b...like
>
> a="why cannot I still write c++ code";

Nice grammar. :-)

> b="c++ code";
>
> a.find_first_not_of(b);

Nice try. Too bad the OP's question was to find out whether or
not characters in a are a subset of b. The above fails that for
several reasons. First of all, you have the contents of a and b
backwards. Secondly, this gets the index of the first character
that doesn't match, not a boolean answer, at least as written.

> That is what we call sleek C++ code in the UNITED STATES OF AMERICA!

It is? I didn't realize that "sleek" meant "fails to meet
program objectives".


> Now, re-read it 100 times and admit that above posts are flawed,
> erronous, completely bizzare and ultimately useless.

Your post was in fact flawed, erroneous (note the spelling),
somewhat bizarre, and ultimately probably not worth responding
to here.

Randy Howard

unread,
Sep 28, 2005, 6:51:43 PM9/28/05
to
August Karlstrom wrote
(in article <XSE_e.147284$dP1.5...@newsc.telia.net>):

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?

> Otherwise comp.lang.c++ is be the appropriate group to consult.

Looked pretty much like conventional C to me. strspn conforms
to ISO C90 according to man pages on this box. :-)

>> I'm having pascal flashbacks, make it stop.
>
> The similarities between Pascal and Oberon is mostly at the syntactic
> level.

Precisely my point. :-)

August Karlstrom

unread,
Sep 28, 2005, 7:19:46 PM9/28/05
to

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

puzzlecracker

unread,
Sep 28, 2005, 8:44:22 PM9/28/05
to

> 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

C'mon people- embrace the reality. Oberon is the next language to
become obsolete with the record of minimum time used in professionally.
The very inception and aims of the language had not fulfilled its
prophesies, nor solved any real-world problems. Its lack of
inheritance, dynamic memory, templates virtual tables, polymorphism,
support for distributive and internet programming as well as scripting,
pattern matching and nonexistent support for regular expression, makes
it a soar thumb in the world of programming and among powerhouses. I
don't want to brag about the past, present and future of C++, for it's
in fact well-known and quite anticipated. I strongly encourage those
neophytes dwelling in world of surrealism to wake up, disengage the
spirit of devil Oberon and join the camp of the world bravest,
toughest, serving - C++ developers. Did you know that world's total
C++ developers outnumber the entire population of Brazil? We are
comparable to a religion whose prophesies are always fulfilled and
exalted.


rules,

ps. I should start writing bi-weekly articles on philosophy of C++ -
its myths and legends.

any suggestions?

Randy Howard

unread,
Sep 28, 2005, 10:34:47 PM9/28/05
to
puzzlecracker wrote
(in article
<1127954662.5...@g43g2000cwa.googlegroups.com>):

>
>> 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
>
> C'mon people- embrace the reality. Oberon is the next language to
> become obsolete

I dunno. My money is on Befunge.

> The very inception and aims of the language had not fulfilled its
> prophesies,

Sounds EXACTLY like C++, and a host of other languages of
varying degrees of popularity.

> nor solved any real-world problems.

Dunno about that one, not being an Oberon person.

> Its lack of
> inheritance, dynamic memory, templates virtual tables, polymorphism,
> support for distributive and internet programming as well as scripting,
> pattern matching and nonexistent support for regular expression,

You may or may not be aware that there are a lot of very, very
popular languages that are missing one or more of the above.

> makes it a soar thumb in the world of programming

^^^^
I didn't realize it had reached such lofty levels. :-)

> don't want to brag about the past, present and future of C++, for it's
> in fact well-known and quite anticipated.

The future of C++ is looking bleaker by the day, sorry to be the
bearer of bad news.

> Did you know that world's total C++ developers outnumber the entire
> population of Brazil?

That's probably just those that are busy trying to debug
multiple inheritance problems. :-)

> We are comparable to a religion whose prophesies are always
> fulfilled and exalted.

Well, your spin does sound very much like religious zealotry,
I'll give you that much.

> ps. I should start writing bi-weekly articles on philosophy of C++ -
> its myths and legends.
>
> any suggestions?

Yes. Don't.

puzzlecracker

unread,
Sep 29, 2005, 12:15:30 AM9/29/05
to

Randy you are mean,

I believe in above statements and they are valid due to above strong,
unequivocal arguments. The truth is obvious. let's embrace it.

Randy Howard

unread,
Sep 29, 2005, 2:18:51 AM9/29/05
to
puzzlecracker wrote
(in article
<1127967330....@g49g2000cwa.googlegroups.com>):

> Randy you are mean,

You actually expected people to take that fan-boy stuff
seriously? You're joking, right?

> I believe in above statements and they are valid due to above strong,
> unequivocal arguments.

I must have missed the strong, unequivocal part. Or perhaps you
left it out by mistake?

> The truth is obvious.

True, but it's not what you think it is.

> let's embrace it.

I have.

August Karlstrom

unread,
Sep 29, 2005, 10:02:39 AM9/29/05
to
Randy Howard wrote:
> puzzlecracker wrote
>>>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
>>
>>C'mon people- embrace the reality. Oberon is the next language to
>>become obsolete
>
>
> I dunno. My money is on Befunge.
>
>
>>The very inception and aims of the language had not fulfilled its
>>prophesies,
>
>
> Sounds EXACTLY like C++, and a host of other languages of
> varying degrees of popularity.
>
>
>>nor solved any real-world problems.
>
>
> Dunno about that one, not being an Oberon person.
>
>
>>Its lack of
>>inheritance, dynamic memory, templates virtual tables, polymorphism,
>>support for distributive and internet programming as well as scripting,
>>pattern matching and nonexistent support for regular expression,
>
>
> You may or may not be aware that there are a lot of very, very
> popular languages that are missing one or more of the above.

puzzlecracker is a troll. Please don't feed it, ignore it.


August

0 new messages