wxString Find in Unicode 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
kea_
Experienced Solver
Experienced Solver
Posts: 59
Joined: Wed Oct 17, 2007 7:32 am

wxString Find in Unicode

Post by kea_ »

Hello together,

first I programmed width ansi and now I do it width unicode.

Now my problem.
I have classes created in ansi they uses the wxString::Find() function. But unfortunately it wouldn't work like before.

Example 1:
wxString s = wxString::FromUTF8("hallo = aaäöaa");
int i = s.Find(_T("="));

That returns -1

Example 2:
wxString s = wxString::FromUTF8("hallo = aaa");
int i = s.Find(_T("="));

That returns 6

Has any body a hint.

Thanks for your help
kea_
User avatar
doublemax
Moderator
Moderator
Posts: 19159
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

Code: Select all

wxString s = wxString::FromUTF8("hallo = aaäöaa"); 
"aaäöaa" is not UTF8 and s is probably empty. In most cases you should be able to write:

Code: Select all

wxString s = wxT("hallo = aaäöaa");
It actually depends on what encoding your editor uses for the text and what encoding your compiler expects.
Use the source, Luke!
kea_
Experienced Solver
Experienced Solver
Posts: 59
Joined: Wed Oct 17, 2007 7:32 am

Post by kea_ »

Thanks for your answer,

it seems to be an unicode problem.
Because I compiled the wxWidgets-2.8.9 widthout unicode an created width code::blocks a new wxWidget-Project width not enabled unicode an the find works fine.

wxString s = "key = aaäa";
int i = s.Find("=");
result: 4

I've had a look in the web and didn't find any help so I think I will go back to ansi.

Thanks for your help
kea_
Post Reply