Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Plugins development => Topic started by: killerbot on November 02, 2005, 01:15:08 pm

Title: wxString problem
Post by: killerbot 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
Title: Re: wxString problem
Post by: thomas on November 02, 2005, 01:26:34 pm
http://www.wxwidgets.org/manuals/2.6.2/wx_wxfilename.html#wxfilenamegetpath
Title: Re: wxString problem
Post by: killerbot on November 02, 2005, 01:28:46 pm
how superb !!


THANKS !!!  :D
Title: Re: wxString problem
Post by: Pecan 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