一个弱弱的问题--wxString Topic is solved

这是wxWidgets论坛的中文版本。在这里,您可以用您的母语汉语讨论上面任一子论坛所涉及的所有关于wxWidgets的话题。欢迎大家参与到对有价值的帖子的中英互译工作中来!
Post Reply
adream307
Earned a small fee
Earned a small fee
Posts: 20
Joined: Thu Oct 02, 2008 6:45 am

一个弱弱的问题--wxString

Post by adream307 » Sat Oct 04, 2008 8:47 am

再次问一个弱弱的问题:
在wxWidgets中,如何把unsigned char *str类型的字符串复制给wxString。
例如:
unsigned char *str="123";
wxString s;
如何使s的内容成为"123"?
直接 s=str;编译出错。
谢谢!

Utensil
Moderator
Moderator
Posts: 423
Joined: Sun Feb 03, 2008 11:38 am
Location: China

Post by Utensil » Sat Oct 04, 2008 12:01 pm

s = wxString(str); 应该可以了。

也可以这样:

wxString s = _T("123");
In fascination of creating worlds by words, and in pursuit of words behind the world.

On Github: http://utensil.github.com
Technical Blog in Chinese: http://utensil.iteye.com/

adream307
Earned a small fee
Earned a small fee
Posts: 20
Joined: Thu Oct 02, 2008 6:45 am

Post by adream307 » Sat Oct 04, 2008 3:28 pm

s=(wxString)str不行,编译还是出错。
我想要的是将一个char *类型的字符串转换成wxString类型的。
谢谢!

Loaden
I live to help wx-kind
I live to help wx-kind
Posts: 177
Joined: Tue Feb 19, 2008 10:21 am
Location: China

Post by Loaden » Sat Oct 04, 2008 11:29 pm

Code: Select all

unsigned char *str="123"; 
wxString s(str);
用构造函数!
Life is not fair, get used to it.

Utensil
Moderator
Moderator
Posts: 423
Joined: Sun Feb 03, 2008 11:38 am
Location: China

Post by Utensil » Sat Oct 04, 2008 11:34 pm

不是(wxString)str,是wxString(str)。两个是完全不同的。你用的那个是类型转换,是不存在的。我说的那个是构造函数。

请多翻阅文档:http://docs.wxwidgets.org/stable/wx_wxs ... inwxstring

你的是Unicode build吗?那么可能得这样做:

const char* ascii_str = "Some text";
wxString str(ascii_str, wxConvUTF8);
In fascination of creating worlds by words, and in pursuit of words behind the world.

On Github: http://utensil.github.com
Technical Blog in Chinese: http://utensil.iteye.com/

arust
Knows some wx things
Knows some wx things
Posts: 34
Joined: Tue Jan 15, 2008 5:13 am
Location: Beijing, China

Post by arust » Fri Mar 27, 2009 9:33 am

我是这样做的

#if wxUSE_UNICODE
#define WX2C(x) (wxString(x).mb_str(wxConvUTF8).data())
#else
#define WX2C(x) (wxString(x).mb_str(wxConvUTF8))
#endif

#define C2WX(x) (wxString(x, wxConvUTF8))

liuyug
Experienced Solver
Experienced Solver
Posts: 53
Joined: Wed Jul 09, 2008 4:32 am

Re: 一个弱弱的问题--wxString

Post by liuyug » Sun Mar 29, 2009 12:47 pm

adream307 wrote:再次问一个弱弱的问题:
在wxWidgets中,如何把unsigned char *str类型的字符串复制给wxString。
例如:
unsigned char *str="123";
wxString s;
如何使s的内容成为"123"?
直接 s=str;编译出错。
谢谢!
wxString::FromAscii((char*)str);

morya
Experienced Solver
Experienced Solver
Posts: 96
Joined: Fri Dec 14, 2007 2:29 am
Location: Xuzhou, China

Post by morya » Wed Apr 08, 2009 8:18 am

我都是
wxString s = wxT("Some text");

regardless of Unicode/ANSI version.

Post Reply