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
Earned a small fee
Earned a small fee
Posts: 17
Joined: Fri Jul 05, 2019 8:47 pm

Problem with a percentage (%) sign in wxString

Post by YuMERA » Thu Sep 05, 2019 4:28 pm

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
Earned some good credits
Earned some good credits
Posts: 125
Joined: Tue Jun 07, 2016 1:07 pm

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

Post by Kvaz1r » Thu Sep 05, 2019 5:31 pm

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

Code: Select all

wxString::Format("%%%s%%", "abs")

YuMERA
Earned a small fee
Earned a small fee
Posts: 17
Joined: Fri Jul 05, 2019 8:47 pm

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

Post by YuMERA » Thu Sep 05, 2019 6:29 pm

Thanks, that's it

Post Reply