Author Topic: wxString problem  (Read 9112 times)

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5514
wxString problem
« on: November 02, 2005, 01:15:08 pm »
Hi,

From my current active build editor I am getting the filename (easy : cbEditor::GetFileName). Next I want to have the path of it.
So I do a very stupid search on the last '\'. (on winblows that is ...)

int pos = Filename.find(_T('\\'), true), where the second argument means find from the end of the string.

It seems that the second arg is of no importance, I get an identical result as if I would specify false, == search from the start.

My filename is for example : "D:\dir\test.cpp",  search from begining (false), or the end (true) both return position 2.

Anyone else stumbled across this problem ??


kind regards,
Lieven
« Last Edit: November 02, 2005, 08:39:25 pm by killerbot »

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5514
Re: wxString problem
« Reply #2 on: November 02, 2005, 01:28:46 pm »
how superb !!


THANKS !!!  :D

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2808
Re: wxString problem
« Reply #3 on: November 02, 2005, 07:32:22 pm »
Yep, wxString::find('somechar', true) seems to be broken.

However, wxString::rfind(...) still works. Here's a snippet..

Code
    wxTextCtrl *control = new wxTextCtrl( m_pwxPanel,
                                -1,                 //wxWindowID id,
                                "",                 //const wxString& value = "",
                                wxPoint(0,0),       //const wxPoint& pos = wxDefaultPosition,
                                wxSize(500,500)     //const wxSize& size = wxDefaultSize, long style = 0,
                                //const wxValidator& validator = wxDefaultValidator,
                                //const wxString& name = wxTextCtrlNameStr
                                );


wxString sPathname=_T("c:\\usr\\proj\\temp\\test.cpp");
size_t lth = sPathname.length();
int pos = sPathname.find('\\', true);
int cpos = sPathname.find('p', true);
        int rpos = sPathname.rfind('\\');

    *control << " len:" << (int)lth <<" pos:"<< pos ;
    *control << " cpos:" << cpos;
    *control << " rpos:" << rpos;
    //results are:  len:25 pos:2 cpos:7 rpos:16


Thanks for the heads-up Lieven
Pecan