Problem with a percentage (%) sign in wxString 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
YuMERA
Knows some wx things
Knows some wx things
Posts: 44
Joined: Fri Jul 05, 2019 8:47 pm

Problem with a percentage (%) sign in wxString

Post by YuMERA »

Hi! How do I handle this?

I have SQL Query

Code: Select all

    scFindItem->SetValue("Pivo")   
       	wxString SQL = wxString::Format(_T("SELECT ID_art, naziv_art, kolicina_art, cena_art, grupa_naziv, grupa_ID, grupa_art "
                                         "FROM artikli,grupa "
                                         "WHERE grupa_art = grupa_ID AND "
                                         "naziv_art LIKE('%%s%')"),scFindItem->GetValue());
the result of that string is
SELECT ID_art, naziv_art, kolicina_art, cena_art, grupa_naziv, grupa_ID, grupa_art FROM artikli,grupa WHERE grupa_art = grupa_ID AND naziv_art LIKE('%s')
must be
SELECT ID_art, naziv_art, kolicina_art, cena_art, grupa_naziv, grupa_ID, grupa_art FROM artikli,grupa WHERE grupa_art = grupa_ID AND naziv_art LIKE('Pivo')
problem is from LIKE('%%s%')
Kvaz1r
Super wx Problem Solver
Super wx Problem Solver
Posts: 357
Joined: Tue Jun 07, 2016 1:07 pm

Re: Problem with a percentage (%) sign in wxString

Post by Kvaz1r »

For escaping '%' you can double it.
Example:

Code: Select all

wxString::Format("%%%s%%", "abs")
YuMERA
Knows some wx things
Knows some wx things
Posts: 44
Joined: Fri Jul 05, 2019 8:47 pm

Re: Problem with a percentage (%) sign in wxString

Post by YuMERA »

Thanks, that's it
Post Reply