News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

wxString problem

Started by killerbot, November 02, 2005, 01:15:08 PM

Previous topic - Next topic

killerbot

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

thomas

"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

killerbot


Pecan

Yep, wxString::find('somechar', true) seems to be broken.

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


    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