How to add quotes to string in Swift?












2















I want to add double quotes around specific substrings in a string viz.: "This is my "QuotedString" in statement".
I have tried :



let quotedString = String(format:"This is my "%@" in statement",QuotedString)


But this creates :
"This is my "QuotedString" in statement".










share|improve this question




















  • 3





    Your code should work. Question is "Where do you see that output"? Debugger? Try to put it into a UILabel, a UITextView, etc. and the backslash shouldn't appear.

    – Larme
    Dec 29 '18 at 16:22
















2















I want to add double quotes around specific substrings in a string viz.: "This is my "QuotedString" in statement".
I have tried :



let quotedString = String(format:"This is my "%@" in statement",QuotedString)


But this creates :
"This is my "QuotedString" in statement".










share|improve this question




















  • 3





    Your code should work. Question is "Where do you see that output"? Debugger? Try to put it into a UILabel, a UITextView, etc. and the backslash shouldn't appear.

    – Larme
    Dec 29 '18 at 16:22














2












2








2








I want to add double quotes around specific substrings in a string viz.: "This is my "QuotedString" in statement".
I have tried :



let quotedString = String(format:"This is my "%@" in statement",QuotedString)


But this creates :
"This is my "QuotedString" in statement".










share|improve this question
















I want to add double quotes around specific substrings in a string viz.: "This is my "QuotedString" in statement".
I have tried :



let quotedString = String(format:"This is my "%@" in statement",QuotedString)


But this creates :
"This is my "QuotedString" in statement".







swift string






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 29 '18 at 17:00









rmaddy

240k27315379




240k27315379










asked Dec 29 '18 at 16:17









ShirishShirish

709




709








  • 3





    Your code should work. Question is "Where do you see that output"? Debugger? Try to put it into a UILabel, a UITextView, etc. and the backslash shouldn't appear.

    – Larme
    Dec 29 '18 at 16:22














  • 3





    Your code should work. Question is "Where do you see that output"? Debugger? Try to put it into a UILabel, a UITextView, etc. and the backslash shouldn't appear.

    – Larme
    Dec 29 '18 at 16:22








3




3





Your code should work. Question is "Where do you see that output"? Debugger? Try to put it into a UILabel, a UITextView, etc. and the backslash shouldn't appear.

– Larme
Dec 29 '18 at 16:22





Your code should work. Question is "Where do you see that output"? Debugger? Try to put it into a UILabel, a UITextView, etc. and the backslash shouldn't appear.

– Larme
Dec 29 '18 at 16:22












2 Answers
2






active

oldest

votes


















5














No, it doesn’t create "This is my "QuotedString" in statement", with the backslashes included. It’s just that when you look at that in the debugger, it includes those backslashes to help you identify the quotes within quoted string (just like you did when you created the string).



But if you use that resulting string in a text field or label, and you’ll see it’s fine, that those backslashes are not really part of the string. Or look at the count of that string, and you’ll see that those backslashes are not included there, either. Those backslashes are merely a byproduct of how you happen to be examining this variable.






share|improve this answer


























  • Thanks. I was stuck in debugging mode . It works. Although it prints while debugging .

    – Shirish
    Dec 30 '18 at 8:21



















1














are used as escape sequences in regular expression. While you are debugging your code, it evaluates it as regular expression. So you see in string. Try to print string on console and see the output.






share|improve this answer























    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%2f53971215%2fhow-to-add-quotes-to-string-in-swift%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









    5














    No, it doesn’t create "This is my "QuotedString" in statement", with the backslashes included. It’s just that when you look at that in the debugger, it includes those backslashes to help you identify the quotes within quoted string (just like you did when you created the string).



    But if you use that resulting string in a text field or label, and you’ll see it’s fine, that those backslashes are not really part of the string. Or look at the count of that string, and you’ll see that those backslashes are not included there, either. Those backslashes are merely a byproduct of how you happen to be examining this variable.






    share|improve this answer


























    • Thanks. I was stuck in debugging mode . It works. Although it prints while debugging .

      – Shirish
      Dec 30 '18 at 8:21
















    5














    No, it doesn’t create "This is my "QuotedString" in statement", with the backslashes included. It’s just that when you look at that in the debugger, it includes those backslashes to help you identify the quotes within quoted string (just like you did when you created the string).



    But if you use that resulting string in a text field or label, and you’ll see it’s fine, that those backslashes are not really part of the string. Or look at the count of that string, and you’ll see that those backslashes are not included there, either. Those backslashes are merely a byproduct of how you happen to be examining this variable.






    share|improve this answer


























    • Thanks. I was stuck in debugging mode . It works. Although it prints while debugging .

      – Shirish
      Dec 30 '18 at 8:21














    5












    5








    5







    No, it doesn’t create "This is my "QuotedString" in statement", with the backslashes included. It’s just that when you look at that in the debugger, it includes those backslashes to help you identify the quotes within quoted string (just like you did when you created the string).



    But if you use that resulting string in a text field or label, and you’ll see it’s fine, that those backslashes are not really part of the string. Or look at the count of that string, and you’ll see that those backslashes are not included there, either. Those backslashes are merely a byproduct of how you happen to be examining this variable.






    share|improve this answer















    No, it doesn’t create "This is my "QuotedString" in statement", with the backslashes included. It’s just that when you look at that in the debugger, it includes those backslashes to help you identify the quotes within quoted string (just like you did when you created the string).



    But if you use that resulting string in a text field or label, and you’ll see it’s fine, that those backslashes are not really part of the string. Or look at the count of that string, and you’ll see that those backslashes are not included there, either. Those backslashes are merely a byproduct of how you happen to be examining this variable.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Dec 29 '18 at 16:36

























    answered Dec 29 '18 at 16:26









    RobRob

    298k49556724




    298k49556724













    • Thanks. I was stuck in debugging mode . It works. Although it prints while debugging .

      – Shirish
      Dec 30 '18 at 8:21



















    • Thanks. I was stuck in debugging mode . It works. Although it prints while debugging .

      – Shirish
      Dec 30 '18 at 8:21

















    Thanks. I was stuck in debugging mode . It works. Although it prints while debugging .

    – Shirish
    Dec 30 '18 at 8:21





    Thanks. I was stuck in debugging mode . It works. Although it prints while debugging .

    – Shirish
    Dec 30 '18 at 8:21













    1














    are used as escape sequences in regular expression. While you are debugging your code, it evaluates it as regular expression. So you see in string. Try to print string on console and see the output.






    share|improve this answer




























      1














      are used as escape sequences in regular expression. While you are debugging your code, it evaluates it as regular expression. So you see in string. Try to print string on console and see the output.






      share|improve this answer


























        1












        1








        1







        are used as escape sequences in regular expression. While you are debugging your code, it evaluates it as regular expression. So you see in string. Try to print string on console and see the output.






        share|improve this answer













        are used as escape sequences in regular expression. While you are debugging your code, it evaluates it as regular expression. So you see in string. Try to print string on console and see the output.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 29 '18 at 17:17









        Vikas KeskarVikas Keskar

        513




        513






























            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%2f53971215%2fhow-to-add-quotes-to-string-in-swift%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

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas