How do you compare two wxString's?

1,991 views
Skip to first unread message

Daniel Carrera

unread,
Jan 19, 2010, 10:45:43 AM1/19/10
to wx-u...@googlegroups.com
Hello,

What's the correct way to compare two wxStrings? I tried Googling for an
answer but couldn't find anything.

Daniel.

Eran Ifrah

unread,
Jan 19, 2010, 11:09:17 AM1/19/10
to wx-u...@googlegroups.com
str1 == str2

or

str1.Cmp(str2) == 0

or

str1.CmpNoCase(str2) == 0

Eran

Daniel Carrera

unread,
Jan 19, 2010, 11:17:56 AM1/19/10
to wx-u...@googlegroups.com
Eran Ifrah wrote:
> str1 == str2

Really? You can tell I'm new to C++. Unless I'm confused, in C that
wouldn't work. I've been assuming that C++ strings would resemble C
strings and that wxString is some special wrapper and that I have to use
special methods to work on them.

Is wxString just the same as a regular C++ string then? If so, why do we
need wxString?

> or
>
> str1.Cmp(str2) == 0
>
> or
>
> str1.CmpNoCase(str2) == 0

Thanks.

Daniel.

iko...@earthlink.net

unread,
Jan 19, 2010, 11:46:52 AM1/19/10
to wx-u...@googlegroups.com
Daniel,


-----Original Message-----
>From: Daniel Carrera <dcar...@gmail.com>
>Sent: Jan 19, 2010 11:17 AM
>To: wx-u...@googlegroups.com
>Subject: Re: How do you compare two wxString's?
>
>Eran Ifrah wrote:
>> str1 == str2
>
>Really? You can tell I'm new to C++. Unless I'm confused, in C that
>wouldn't work. I've been assuming that C++ strings would resemble C
>strings and that wxString is some special wrapper and that I have to use
>special methods to work on them.
>
>Is wxString just the same as a regular C++ string then? If so, why do we
>need wxString?

Define "regular C++ string", please.

Thank you.

Daniel Carrera

unread,
Jan 19, 2010, 12:06:17 PM1/19/10
to wx-u...@googlegroups.com
iko...@earthlink.net wrote:
>> Is wxString just the same as a regular C++ string then? If so, why do we
>> need wxString?
>
> Define "regular C++ string", please.

There isn't an agreed definition on what a normal C++ string is? I would
have thought that std::string would be it. But I'm new at C++ so I might
be missing something fundamental.

Daniel.

Daniel Carrera

unread,
Jan 19, 2010, 12:14:02 PM1/19/10
to wx-u...@googlegroups.com
I found a page that talks about the benefits of wxString:

http://docs.wxwidgets.org/stable/wx_wxstringoverview.html

Cheers,
Daniel.

iko...@earthlink.net

unread,
Jan 19, 2010, 12:14:43 PM1/19/10
to wx-u...@googlegroups.com
Daniel,


-----Original Message-----
>From: Daniel Carrera <dcar...@gmail.com>
>Sent: Jan 19, 2010 9:06 AM
>To: wx-u...@googlegroups.com
>Subject: Re: How do you compare two wxString's?
>

And what it will be on platforms where std::string/STL is _not_ available?
That's why wxWidgets can be configured to not use STL and use it's own
implementation.
But that is only one part of it....

Thank you.

>
>Daniel.

Leslie Newell

unread,
Jan 19, 2010, 12:21:10 PM1/19/10
to wx-u...@googlegroups.com
Hi Daniel

> Really? You can tell I'm new to C++. Unless I'm confused, in C that
> wouldn't work. I've been assuming that C++ strings would resemble C
> strings and that wxString is some special wrapper and that I have to
> use special methods to work on them.
>
> Is wxString just the same as a regular C++ string then? If so, why do
> we need wxString?

No that wouldn't work in C. This is one of the big advantages of C++.
What happens is that the wxString class overrides the == operator. s1 ==
s2 is functionally equivalent to calling:
s1.operator ==(s2)
When you do this you are really calling a function something like this:
wxString& operator == (const wxString& source)
{
code to perform the comparison here...
return(*this);
}

Les

Daniel Carrera

unread,
Jan 19, 2010, 1:48:56 PM1/19/10
to wx-u...@googlegroups.com
Leslie Newell wrote:
> No that wouldn't work in C. This is one of the big advantages of C++.
> What happens is that the wxString class overrides the == operator.

Indeed. I can see how that C++ has a lot more merit than I thought. I've
always avoided learning C++ because I keep hearing about how complicated
it is and how it is a huge language and so on.

But I can see that for my own work I can ignore 99% of the complexity of
C++ and just pick the bits and pieces that would make C more fun to use.

Cheers,
Daniel.

Brian Ravnsgaard Riis

unread,
Jan 19, 2010, 4:28:43 PM1/19/10
to wx-u...@googlegroups.com
Daniel Carrera skrev:

This is actually the preferred way to proceed to C++ if you already know
C. Always do 90% of your coding using what you already know, and pick up
new features in the remaining 10%. This does mean, in the beginning,
that you'll be using C++ as merely a "better C," but this is quite all
right. You can always add more features when you get more experience
under your belt. :-)

/Brian

Kenneth Porter

unread,
Jan 20, 2010, 8:58:56 PM1/20/10
to wx-u...@googlegroups.com
--On Tuesday, January 19, 2010 9:14 AM -0800 iko...@earthlink.net wrote:

> And what it will be on platforms where std::string/STL is _not_ available?

Isn't std::string a required part of any standards-compliant C++ platform?
The STL was adopted as part of the ANSI standard language quite some time
ago, so platforms that lack it are either quite old or non-compliant.


Reply all
Reply to author
Forward
0 new messages