QString.mid, QString.right not working right with Spanish characters



  • Given this code:

    qDebug() << "raw payload" << gmcpPayload;
    qDebug() << "remove first 3 and last 2 with mid" << gmcpPayload.mid(3, command.size() - 5);
    qDebug() << "remove just first 3 with mid" << gmcpPayload.mid(3);
    qDebug() << "remove just last 2 with right" << gmcpPayload.right(command.size() - 2);
    

    I get the following output:

    raw payload "���Char.Name { \"name\": \"Vadimuses\", \"fullname\": \"Lord Vadimuses Xanatov, Pure Disciple\" }��"
    remove first 3 and last 2 with mid "Char.Name { \"name\": \"Vadimuses\", \"fullname\": \"Lord Vadimuses Xanatov, Pure Disciple\" }"
    remove just first 3 with mid "Char.Name { \"name\": \"Vadimuses\", \"fullname\": \"Lord Vadimuses Xanatov, Pure Disciple\" }��"
    remove just last 2 with left "���Char.Name { \"name\": \"Vadimuses\", \"fullname\": \"Lord Vadimuses Xanatov, Pure Disciple\" }"
    

    Looks good! Everything I want. But if my text starts having á's and ñ's, it fails:

    raw payload "���Char.Hellos\n\"lalalá123ññ45\"��"
    remove first 3 and last 2 with mid "Char.Hellos\n\"lalalá123ññ45\"��"
    remove just first 3 with mid "Char.Hellos\n\"lalalá123ññ45\"��"
    remove just last 2 with left "���Char.Hellos\n\"lalalá123ññ45\"��"
    

    What I expect instead is:

    raw payload "���Char.Hellos\n\"lalalá123ññ45\"��"
    remove first 3 and last 2 with mid "Char.Hellos\n\"lalalá123ññ45\""
    remove just first 3 with mid "Char.Hellos\n\"lalalá123ññ45\"��"
    remove just last 2 with left "���Char.Hellos\n\"lalalá123ññ45\""
    

    How come the removal of the last two unprintable characters (255 and 240 for the curious) fails when non-Latin characters are involved?



  • Was getting the .size() from the wrong string...


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.