Finding text 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
sethjackson
Super wx Problem Solver
Super wx Problem Solver
Posts: 396
Joined: Wed Oct 05, 2005 1:19 am

Finding text

Post by sethjackson »

Editor derives from wxTextCtrl. :)

Code: Select all

bool Editor::Find(const wxString& find, int flags)
{
    m_findString = find;
    m_findFlags = flags;

    //SetSelection(GetInsertionPoint(), GetInsertionPoint());
    wxString string;

    if (flags & wxFR_DOWN)
        string = GetRange(GetInsertionPoint(), GetLastPosition());

    else
        string = wxEmptyString;

    if (flags & wxFR_MATCHCASE)
        m_foundPos = string.find(find);

    else
        m_foundPos = string.Lower().find(find);

    long startPos;

    if (flags & wxFR_DOWN)
        startPos = GetInsertionPoint() + m_foundPos;

    else
        startPos = 0;

    long endPos = startPos + find.length();

    SetSelection(startPos, endPos);

    return true;
}
I want to know how to do upward search. However I'm not getting it.....

I assume I need to use GetRange() somehow, but wont that return the string backwards?
protocol
Moderator
Moderator
Posts: 680
Joined: Wed Jan 18, 2006 6:13 pm
Location: Dallas, TX
Contact:

Post by protocol »

Just reverse the text you are searching through and then begin the find.
/* UIKit && wxWidgets 2.8 && Cocoa && .Net */
QuRegExmm
wxPCRE & ObjPCRE - Regex It!
sethjackson
Super wx Problem Solver
Super wx Problem Solver
Posts: 396
Joined: Wed Oct 05, 2005 1:19 am

Post by sethjackson »

protocol wrote:Just reverse the text you are searching through and then begin the find.
How to do that?
DavidHart
Site Admin
Site Admin
Posts: 4254
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Post by DavidHart »

Hi,

Assuming that I understand correctly what you're doing/asking, you should be able to get the portion of the string to search by using string = GetRange(0, GetInsertionPoint()); and then use rfind instead of find.

Regards,

David
sethjackson
Super wx Problem Solver
Super wx Problem Solver
Posts: 396
Joined: Wed Oct 05, 2005 1:19 am

Post by sethjackson »

DavidHart wrote:Hi,

Assuming that I understand correctly what you're doing/asking, you should be able to get the portion of the string to search by using string = GetRange(0, GetInsertionPoint()); and then use rfind instead of find.

Regards,

David
Duh. Thanks. :D
sethjackson
Super wx Problem Solver
Super wx Problem Solver
Posts: 396
Joined: Wed Oct 05, 2005 1:19 am

Post by sethjackson »

protocol wrote:In support to what DavidHart posted:
wxWidgets Doc wrote: // rfind() family is exactly like find() but works right to left

// as find, but from the end
size_t rfind(const wxString& str, size_t nStart = npos) const;

// as find, but from the end
size_t rfind(const char* sz, size_t nStart = npos,
size_t n = npos) const;
// as find, but from the end
size_t rfind(char ch, size_t nStart = npos) const;
best regards.
Yeah I can't believe I missed that. :P

Thanks again for the help. :)
Post Reply