Using wxChar in a switch statement Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
nexes
In need of some credit
In need of some credit
Posts: 9
Joined: Sat Feb 18, 2006 12:44 am

Using wxChar in a switch statement

Post by nexes »

Code: Select all

       switch ( (const char) ((tempString.SubString(tempString.Length()-1, tempString.Length()-1)).mb_str(wxConvUTF8))[0] )
       {
          case 'h':
          break;
       }
Is there a cleaner way of converting a wxString into a char?
protocol
Moderator
Moderator
Posts: 680
Joined: Wed Jan 18, 2006 6:13 pm
Location: Dallas, TX
Contact:

Post by protocol »

I'm not really sure if your substring is doing anything special, because wxString implements the array operator.

Code: Select all

wxString str = "good";
wxChar c = str[1]; // returns 'o'
Review the wxString documentation here.
http://www.wxwidgets.org/manuals/2.6.2/wx_wxstring.html

Hope that helps. Let me know if you need any more examples.
/* UIKit && wxWidgets 2.8 && Cocoa && .Net */
QuRegExmm
wxPCRE & ObjPCRE - Regex It!
nexes
In need of some credit
In need of some credit
Posts: 9
Joined: Sat Feb 18, 2006 12:44 am

Post by nexes »

protocol wrote:I'm not really sure if your substring is doing anything special, because wxString implements the array operator.

Code: Select all

wxString str = "good";
wxChar c = str[1]; // returns 'o'
Review the wxString documentation here.
http://www.wxwidgets.org/manuals/2.6.2/wx_wxstring.html

Hope that helps. Let me know if you need any more examples.
Ahh, yes, the array operator. Hmm, that would make it partly cleaner.

Can you tell me if I can use a wxChar in a switch statement? Or do I have to cast it into the char like I have?
cecilio
I live to help wx-kind
I live to help wx-kind
Posts: 189
Joined: Fri Dec 03, 2004 8:44 am
Location: spain
Contact:

Post by cecilio »

Yes, you can use an wxChar in a switch statement. For example:

wxChar cStep = sStep.GetChar(0);
switch (cStep) {
case L'c':
leio
Can't get richer than this
Can't get richer than this
Posts: 802
Joined: Mon Dec 27, 2004 10:46 am
Location: Estonia, Tallinn
Contact:

Post by leio »

Code: Select all

case wxT('c'):
No particular need to break non-unicode builds by using always a wchar_t there, unconditionally disregarding wxwidgets build type.
Compilers: gcc-3.3.6, gcc-3.4.5, gcc-4.0.2, gcc-4.1.0 and MSVC6
OS's: Gentoo Linux, WinXP; WX: CVS HEAD

Project Manager of wxMUD - http://wxmud.sf.net/
Developer of wxGTK;
gtk+ port maintainer of OMGUI - http://www.omgui.org/
cecilio
I live to help wx-kind
I live to help wx-kind
Posts: 189
Joined: Fri Dec 03, 2004 8:44 am
Location: spain
Contact:

Post by cecilio »

Code: Select all

case wxT('c'):
No particular need to break non-unicode builds by using always a wchar_t there, unconditionally disregarding wxwidgets build type.
You are right. Use wxT('x') instead of L'x'. Sorry for the mistake.
nexes
In need of some credit
In need of some credit
Posts: 9
Joined: Sat Feb 18, 2006 12:44 am

Post by nexes »

Thanks everyone!
Post Reply