Modifying a QString that contains a “”How to change string into QString?Qt QString cloning Segmentation FaultQString to char* conversionConvert an int to a QString with zero padding (leading zeroes)How to convert int to QString?How to convert QString to std::string?Convert std::string to QStringWhy is this QString to const char* conversion producing a Debian identifier on Windows?Return a QString from a function - thread safe?Extract character from QString and compare

Why are angular mometum and angular velocity not necessarily parallel, but linear momentum and linear velocity are always parallel?

How can I tell if there was a power cut while I was out?

Company messed up with patent and now a lawyer is coming after me

Why are so many countries still in the Commonwealth?

What is "ass door"?

Current relevance: "She has broken her leg" vs. "She broke her leg yesterday"

Should I leave my PhD after 3 years with a Masters?

How may I shorten this shell script?

How can I create a shape in Illustrator which follows a path in descending order size?

Why is chess failing to attract big name sponsors?

Memory capability and powers of 2

Are gangsters hired to attack people at a train station classified as a terrorist attack?

How can I make sure my players' decisions have consequences?

Talk to manager when quitting my job

What are the exact meanings of roll, pitch and yaw?

What is a Union Word™?

Spacing setting of math mode

What is the meaning of "you has the wind of me"?

Spoken encryption

Is it legal for private citizens to "impound" e-scooters?

Book about young girl who ends up in space after apocolypse

How can I stop myself from micromanaging other PCs' actions?

Can two figures have the same area, perimeter, and same number of segments have different shape?

Invert Some Switches on a Switchboard



Modifying a QString that contains a “”


How to change string into QString?Qt QString cloning Segmentation FaultQString to char* conversionConvert an int to a QString with zero padding (leading zeroes)How to convert int to QString?How to convert QString to std::string?Convert std::string to QStringWhy is this QString to const char* conversion producing a Debian identifier on Windows?Return a QString from a function - thread safe?Extract character from QString and compare






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I'm trying to modify a QString. The Qstring that I'm trying to modify is



"02"


However when I try to modify it, the string either gets entirely deleted or shows no change.



I've tried



String.split(""");
String.remove(""");
String.remove(QChar(''');


for some reason Qt requires that I add an extra " or ' in order to compile and not produce errors



What I currently have is this



string = pointer->data.info.get_type();


which according to the debugger returns "02"



string = string.remove(QChar('''));


the remove functionality does nothing afterwards.



I'm expecting to remove the from the string, but either it gets entirely deleted or nothing happens. What could be the problem and how do I modify the Qstring to just be the numerical values?










share|improve this question

















  • 4





    You should read up about escape sequences in c++ strings. You need "\" not """ to search for a slash, the second one searches for a quote

    – Alan Birtles
    Mar 26 at 15:58











  • You want String.split("\"); , not String.split("""); .

    – Jesper Juhl
    Mar 26 at 15:58











  • Put another way: What would you think is the reason that there are three instances of " in String.split(""");? It appears that the compiler complained about an unclosed string/character literal and you just added a " to shut it up without considering why "" didn't work.

    – Max Langhof
    Mar 26 at 16:14












  • question is about C++ basic, but it is well written question, describing what is expected and what is seen, so I will vote it up.

    – Marek R
    Mar 26 at 16:20


















1















I'm trying to modify a QString. The Qstring that I'm trying to modify is



"02"


However when I try to modify it, the string either gets entirely deleted or shows no change.



I've tried



String.split(""");
String.remove(""");
String.remove(QChar(''');


for some reason Qt requires that I add an extra " or ' in order to compile and not produce errors



What I currently have is this



string = pointer->data.info.get_type();


which according to the debugger returns "02"



string = string.remove(QChar('''));


the remove functionality does nothing afterwards.



I'm expecting to remove the from the string, but either it gets entirely deleted or nothing happens. What could be the problem and how do I modify the Qstring to just be the numerical values?










share|improve this question

















  • 4





    You should read up about escape sequences in c++ strings. You need "\" not """ to search for a slash, the second one searches for a quote

    – Alan Birtles
    Mar 26 at 15:58











  • You want String.split("\"); , not String.split("""); .

    – Jesper Juhl
    Mar 26 at 15:58











  • Put another way: What would you think is the reason that there are three instances of " in String.split(""");? It appears that the compiler complained about an unclosed string/character literal and you just added a " to shut it up without considering why "" didn't work.

    – Max Langhof
    Mar 26 at 16:14












  • question is about C++ basic, but it is well written question, describing what is expected and what is seen, so I will vote it up.

    – Marek R
    Mar 26 at 16:20














1












1








1








I'm trying to modify a QString. The Qstring that I'm trying to modify is



"02"


However when I try to modify it, the string either gets entirely deleted or shows no change.



I've tried



String.split(""");
String.remove(""");
String.remove(QChar(''');


for some reason Qt requires that I add an extra " or ' in order to compile and not produce errors



What I currently have is this



string = pointer->data.info.get_type();


which according to the debugger returns "02"



string = string.remove(QChar('''));


the remove functionality does nothing afterwards.



I'm expecting to remove the from the string, but either it gets entirely deleted or nothing happens. What could be the problem and how do I modify the Qstring to just be the numerical values?










share|improve this question














I'm trying to modify a QString. The Qstring that I'm trying to modify is



"02"


However when I try to modify it, the string either gets entirely deleted or shows no change.



I've tried



String.split(""");
String.remove(""");
String.remove(QChar(''');


for some reason Qt requires that I add an extra " or ' in order to compile and not produce errors



What I currently have is this



string = pointer->data.info.get_type();


which according to the debugger returns "02"



string = string.remove(QChar('''));


the remove functionality does nothing afterwards.



I'm expecting to remove the from the string, but either it gets entirely deleted or nothing happens. What could be the problem and how do I modify the Qstring to just be the numerical values?







c++ qt qstring






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 26 at 15:55









BChiuBChiu

297 bronze badges




297 bronze badges







  • 4





    You should read up about escape sequences in c++ strings. You need "\" not """ to search for a slash, the second one searches for a quote

    – Alan Birtles
    Mar 26 at 15:58











  • You want String.split("\"); , not String.split("""); .

    – Jesper Juhl
    Mar 26 at 15:58











  • Put another way: What would you think is the reason that there are three instances of " in String.split(""");? It appears that the compiler complained about an unclosed string/character literal and you just added a " to shut it up without considering why "" didn't work.

    – Max Langhof
    Mar 26 at 16:14












  • question is about C++ basic, but it is well written question, describing what is expected and what is seen, so I will vote it up.

    – Marek R
    Mar 26 at 16:20













  • 4





    You should read up about escape sequences in c++ strings. You need "\" not """ to search for a slash, the second one searches for a quote

    – Alan Birtles
    Mar 26 at 15:58











  • You want String.split("\"); , not String.split("""); .

    – Jesper Juhl
    Mar 26 at 15:58











  • Put another way: What would you think is the reason that there are three instances of " in String.split(""");? It appears that the compiler complained about an unclosed string/character literal and you just added a " to shut it up without considering why "" didn't work.

    – Max Langhof
    Mar 26 at 16:14












  • question is about C++ basic, but it is well written question, describing what is expected and what is seen, so I will vote it up.

    – Marek R
    Mar 26 at 16:20








4




4





You should read up about escape sequences in c++ strings. You need "\" not """ to search for a slash, the second one searches for a quote

– Alan Birtles
Mar 26 at 15:58





You should read up about escape sequences in c++ strings. You need "\" not """ to search for a slash, the second one searches for a quote

– Alan Birtles
Mar 26 at 15:58













You want String.split("\"); , not String.split("""); .

– Jesper Juhl
Mar 26 at 15:58





You want String.split("\"); , not String.split("""); .

– Jesper Juhl
Mar 26 at 15:58













Put another way: What would you think is the reason that there are three instances of " in String.split(""");? It appears that the compiler complained about an unclosed string/character literal and you just added a " to shut it up without considering why "" didn't work.

– Max Langhof
Mar 26 at 16:14






Put another way: What would you think is the reason that there are three instances of " in String.split(""");? It appears that the compiler complained about an unclosed string/character literal and you just added a " to shut it up without considering why "" didn't work.

– Max Langhof
Mar 26 at 16:14














question is about C++ basic, but it is well written question, describing what is expected and what is seen, so I will vote it up.

– Marek R
Mar 26 at 16:20






question is about C++ basic, but it is well written question, describing what is expected and what is seen, so I will vote it up.

– Marek R
Mar 26 at 16:20













2 Answers
2






active

oldest

votes


















6














You're currently asking Qt to remove " from your string, not . To remove , you'll have to escape it, just like you escaped ", i.e. remove("\").






share|improve this answer






























    3














    First of all your string "02" do not contain any slash, quotes or apostrophes.
    Read about C++ string literals. This is escape sequence.
    Note nnn represents arbitrary octal value!



    So your literal contains only one character of value decimal value 2! This is ASCII spatial code meaning: STX (start of text)



    As a result this code:



    String.split(""");
    String.remove(""");
    String.remove(QChar(''');


    won't split or anything since this string do not contain quote characters or apostrophe. It also do not tries split or remove slash character, since again this is an escape sequence, but different kind.



    Now remember that debugger shows you this unprintable characters in escaped form to show you actual content. In live application user will see nothing or some strange glyph.






    share|improve this answer




















    • 1





      It really depends, maybe "02" is truly what the string contains (i.e. the source code actually has "\002", although I wouldn't bet on that). You got my +1 though because this aspect is indeed important to be aware of here.

      – Max Langhof
      Mar 26 at 16:20














    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55361362%2fmodifying-a-qstring-that-contains-a%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    6














    You're currently asking Qt to remove " from your string, not . To remove , you'll have to escape it, just like you escaped ", i.e. remove("\").






    share|improve this answer



























      6














      You're currently asking Qt to remove " from your string, not . To remove , you'll have to escape it, just like you escaped ", i.e. remove("\").






      share|improve this answer

























        6












        6








        6







        You're currently asking Qt to remove " from your string, not . To remove , you'll have to escape it, just like you escaped ", i.e. remove("\").






        share|improve this answer













        You're currently asking Qt to remove " from your string, not . To remove , you'll have to escape it, just like you escaped ", i.e. remove("\").







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 26 at 15:58









        gsprgspr

        7,6842 gold badges30 silver badges63 bronze badges




        7,6842 gold badges30 silver badges63 bronze badges























            3














            First of all your string "02" do not contain any slash, quotes or apostrophes.
            Read about C++ string literals. This is escape sequence.
            Note nnn represents arbitrary octal value!



            So your literal contains only one character of value decimal value 2! This is ASCII spatial code meaning: STX (start of text)



            As a result this code:



            String.split(""");
            String.remove(""");
            String.remove(QChar(''');


            won't split or anything since this string do not contain quote characters or apostrophe. It also do not tries split or remove slash character, since again this is an escape sequence, but different kind.



            Now remember that debugger shows you this unprintable characters in escaped form to show you actual content. In live application user will see nothing or some strange glyph.






            share|improve this answer




















            • 1





              It really depends, maybe "02" is truly what the string contains (i.e. the source code actually has "\002", although I wouldn't bet on that). You got my +1 though because this aspect is indeed important to be aware of here.

              – Max Langhof
              Mar 26 at 16:20
















            3














            First of all your string "02" do not contain any slash, quotes or apostrophes.
            Read about C++ string literals. This is escape sequence.
            Note nnn represents arbitrary octal value!



            So your literal contains only one character of value decimal value 2! This is ASCII spatial code meaning: STX (start of text)



            As a result this code:



            String.split(""");
            String.remove(""");
            String.remove(QChar(''');


            won't split or anything since this string do not contain quote characters or apostrophe. It also do not tries split or remove slash character, since again this is an escape sequence, but different kind.



            Now remember that debugger shows you this unprintable characters in escaped form to show you actual content. In live application user will see nothing or some strange glyph.






            share|improve this answer




















            • 1





              It really depends, maybe "02" is truly what the string contains (i.e. the source code actually has "\002", although I wouldn't bet on that). You got my +1 though because this aspect is indeed important to be aware of here.

              – Max Langhof
              Mar 26 at 16:20














            3












            3








            3







            First of all your string "02" do not contain any slash, quotes or apostrophes.
            Read about C++ string literals. This is escape sequence.
            Note nnn represents arbitrary octal value!



            So your literal contains only one character of value decimal value 2! This is ASCII spatial code meaning: STX (start of text)



            As a result this code:



            String.split(""");
            String.remove(""");
            String.remove(QChar(''');


            won't split or anything since this string do not contain quote characters or apostrophe. It also do not tries split or remove slash character, since again this is an escape sequence, but different kind.



            Now remember that debugger shows you this unprintable characters in escaped form to show you actual content. In live application user will see nothing or some strange glyph.






            share|improve this answer















            First of all your string "02" do not contain any slash, quotes or apostrophes.
            Read about C++ string literals. This is escape sequence.
            Note nnn represents arbitrary octal value!



            So your literal contains only one character of value decimal value 2! This is ASCII spatial code meaning: STX (start of text)



            As a result this code:



            String.split(""");
            String.remove(""");
            String.remove(QChar(''');


            won't split or anything since this string do not contain quote characters or apostrophe. It also do not tries split or remove slash character, since again this is an escape sequence, but different kind.



            Now remember that debugger shows you this unprintable characters in escaped form to show you actual content. In live application user will see nothing or some strange glyph.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 26 at 16:15

























            answered Mar 26 at 16:10









            Marek RMarek R

            14.9k3 gold badges30 silver badges81 bronze badges




            14.9k3 gold badges30 silver badges81 bronze badges







            • 1





              It really depends, maybe "02" is truly what the string contains (i.e. the source code actually has "\002", although I wouldn't bet on that). You got my +1 though because this aspect is indeed important to be aware of here.

              – Max Langhof
              Mar 26 at 16:20













            • 1





              It really depends, maybe "02" is truly what the string contains (i.e. the source code actually has "\002", although I wouldn't bet on that). You got my +1 though because this aspect is indeed important to be aware of here.

              – Max Langhof
              Mar 26 at 16:20








            1




            1





            It really depends, maybe "02" is truly what the string contains (i.e. the source code actually has "\002", although I wouldn't bet on that). You got my +1 though because this aspect is indeed important to be aware of here.

            – Max Langhof
            Mar 26 at 16:20






            It really depends, maybe "02" is truly what the string contains (i.e. the source code actually has "\002", although I wouldn't bet on that). You got my +1 though because this aspect is indeed important to be aware of here.

            – Max Langhof
            Mar 26 at 16:20


















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55361362%2fmodifying-a-qstring-that-contains-a%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript